0%

C/C++ zero 系列

bzero

  • #include <strings.h>
  • void bzero(void *s, size_t n);
  • The bzero() function erases the data in the n bytes of the memory
  • starting at the location pointed to by s, by writing zeros (bytes containing ‘\0’) to that area.
  • return

C/C++ printf 系列

sprintf

  • #include <stdio.h>, #include <cstdio>
  • int sprintf ( char * str, const char * format, ... );
  • Write formatted data to string
  • A terminating null character is automatically appended after the content.
    閱讀全文 »

Curl in C/C++

編譯與安裝

timedatectl

  • 控制系統的時間與日期,可用於查詢與修改 系統時鐘的各項設置。

  • 是 systemd unit

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 顯示目前狀態
    $ timedatectl
    Local time: Mon 2020-04-06 18:11:32 CST
    Universal time: Mon 2020-04-06 10:11:32 UTC
    RTC time: Mon 2020-04-06 10:11:33
    Time zone: Asia/Taipei (CST, +0800)
    System clock synchronized: yes
    systemd-timesyncd.service active: yes
    RTC in local TZ: no
    閱讀全文 »

Create a big file in Linux

fallocate

  • Preallocate space to a file.
    1
    2
    3
    fallocate [-c|-p|-z] [-o offset] -l length [-n] filename
    fallocate -d [-o offset] [-l length] filename
    fallocate -x [-o offset] -l length filename
    閱讀全文 »

How to tell same-content files on Linux

md5sum

  • md5sum date1.txt date2.txt date3.txt
  • md5sum date1.txt date2.txt date3.txt > date.md5sum
    • -c 的檢查用參數可以自動進行檔案的 MD5 校驗碼比對:
    • md5sum -c date.md5sum
      閱讀全文 »

Mac Check SSD

  • install
    • brew install smartmontools
  • check id

C/C++ 可變參數

  • va在這裏是variable-argument(可變參數)的意思
    • #include stdarg.h
    • va_list 用来定义一个变量列表的指针类型.

introduction

  • 除了有一個參數format固定以外,後面跟的參數的個數和類型是可變的

    1
    int printf( const char* format,...);
    閱讀全文 »

RTTI

  • Run-Time Type Information,也有人寫作 Run-Time Type Identification
  • 代表著執行時期取得物件的型態資訊
  • 在 C++ 中,可以使用定義於 type_infotypeid 來實作。
  • 最單純的RTTI包括﹕
  • ●類別識別(class identification)──包括類別名稱或ID。
  • ●繼承關係(inheritance relationship)──支持執行時期的「往下變換型態」(downward casting)﹐亦即動態轉型態(dynamic casting) 。
  • 在對象數據庫存取上﹐還需要下述RTTI﹕
  • ●對象結構(object layout) ──包括屬性的型態、名稱及其位置(position或offset)。
  • ●成員函數表(table of functions)──包括函數的型態、名稱、及其參數型態等。
  • 其目的是協助對象的I/O 和永存(persistence) ﹐也提供偵錯訊息等。

    introduction

  • typeid用於在執行時辨識型態訊息
  • dynamic_cast具有執行時型態辨識和型態轉換匹配2個功能
  • 實現方法為每個型態對應一個const type_info型態物件,儲存了這個確切型態訊息。
  • 在C++標準標頭檔<typeinfo>中,type_info類多載了operator=()、operator!=()、name()等成員函式。
    閱讀全文 »

SATA

  • SATA是Serial ATA(Serial Advanced Technology Attachment)的縮寫,亦稱串行ATA。它是一種電腦總線,主要功能是用作主機板和大量儲存裝置(如硬碟及光盤驅動器)之間的數據傳輸之用。
  • 序列ATA與序列SCSI(SAS: Serial Attached SCSI)的兩者排線相容,SATA硬碟可接上SAS介面。

    閱讀全文 »