标準的GLib資料類型:
gboolean 真或假,與GLib定義的TRUE和FALSE常量一起使用
gpointer 通用指針,即void *
gchar和guchar 字元和無符号字元
gint、guint、gshort 有符号和無符号資料類型
glong、gulong 長度根據硬體和作業系統體系結構的不同而變化
gint8、guint8、gint16、guint16、gint32、guint32 具有已知長度的有符号和無符号的整數資料類型。
gint64、guint64 64位有符号和無符号整數
gfloat、gdouble 浮點數
gsize 無符号整數
gssize 有符号整數
宏
1.分隔符宏和常量
G_DIR_SEPARATOR 字元,Windows下是'\',Linux下是'/'
G_DIR_SEPARATOR_S 字元串
G_SERACHPATH_SEPARATORPATH分隔符,Windows下是';',Linux下是':'
G_SERACHPATH_SEPARATOR_S 字元串
2.算數宏
MIN(x, y)
MAX(x, y)
ABS(x)
CLAMP(x, y, z) 鎖定給定範圍的一個值
錯誤檢測
g_assert() 條件為假,程式終止
g_assert_not_reached()不應該到達的點,如果執行,則程式将會終止
g_return_if_fail 條件為假,函數傳回,程式不終止
g_return_val_if_fail 增加一個傳回值
g_error() 輸出錯誤消息并終止程式
g_warning() 不終止程式,隻輸出錯誤消息
使用記憶體
g_malloc和g_free,函數失敗将終止應用程式,其工作與malloc和free幾乎相同。
資料結構:
單向連結清單
struct GSList
{
gpointer data;
GSList *next;
}
雙向連結清單
struct GList
{
gpointer data;
GList *next;
GList *prev;
}
建立表是初始化一個表指針為NULL,而不是建立一個空表。
删除表 g_slist_free()、g_list_free()
插入表項 g_slist_append、g_slistprepend、g_list_append、g_list_prepend、g_list_insert
表中移動
單項連結清單 g_slist_next、g_slit_last
雙向連結清單g_list_next、g_list_last、g_list_first、g_list_previous
排序 g_list_sort、g_list_find_custom
樹、散清單、誇克
GTree * g_tree_new(GCompareFunc ComparisonFunction);
g_tree_insert()
g_tree_remove()
g_tree_lookup()
g_tree_traverse()
g_tree_destroy()
擴充資料類型:
GString
g_string_new
g_string_sized_now
g_string_assign
g_string_append
g_string_prepend
g_string_insert
g_string_up
g_string_down
g_string_erase
計時器GTimer
g_timer_new
g_timer_start
g_timer_stop
g_timer_elapsed
g_timer_reset
g_timer_destroy