## 17. glib

glib提供许多有用的函数及定义. 我把它们列在这里并做简短的解释. 很多都是与libc重复, 对这些我不再详述. 这些大致上是用来参考, 您知道有什麽东西可以用就好.

## 17.1 定义

``` G_MINFLOAT G_MAXFLOAT G_MINDOUBLE G_MAXDOUBLE G_MINSHORT G_MAXSHORT G_MININT G_MAXINT G_MINLONG G_MAXLONG ```

``` char gchar; short gshort; long glong; int gint; char gboolean; unsigned char guchar; unsigned short gushort; unsigned long gulong; unsigned int guint; float gfloat; double gdouble; long double gldouble; void* gpointer; gint8 guint8 gint16 guint16 gint32 guint32 ```

## 17.2 双向链结串列

``` GList* g_list_alloc (void); void g_list_free (GList *list); void g_list_free_1 (GList *list); GList* g_list_append (GList *list, gpointer data); GList* g_list_prepend (GList *list, gpointer data); GList* g_list_insert (GList *list, gpointer data, gint position); GList* g_list_remove (GList *list, gpointer data); GList* g_list_remove_link (GList *list, GList *link); GList* g_list_reverse (GList *list); GList* g_list_nth (GList *list, gint n); GList* g_list_find (GList *list, gpointer data); GList* g_list_last (GList *list); GList* g_list_first (GList *list); gint g_list_length (GList *list); void g_list_foreach (GList *list, GFunc func, gpointer user_data); ```

## 17.3 单向链结串列

``` GSList* g_slist_alloc (void); void g_slist_free (GSList *list); void g_slist_free_1 (GSList *list); GSList* g_slist_append (GSList *list, gpointer data); GSList* g_slist_prepend (GSList *list, gpointer data); GSList* g_slist_insert (GSList *list, gpointer data, gint position); GSList* g_slist_remove (GSList *list, gpointer data); GSList* g_slist_remove_link (GSList *list, GSList *link); GSList* g_slist_reverse (GSList *list); GSList* g_slist_nth (GSList *list, gint n); GSList* g_slist_find (GSList *list, gpointer data); GSList* g_slist_last (GSList *list); gint g_slist_length (GSList *list); void g_slist_foreach (GSList *list, GFunc func, gpointer user_data); ```

## 17.4 记忆体管理

``` gpointer g_malloc (gulong size); ```

``` gpointer g_malloc0 (gulong size); ```

``` gpointer g_realloc (gpointer mem, gulong size); ```

``` void g_free (gpointer mem); ```
``` void g_mem_profile (void); ```

``` void g_mem_check (gpointer mem); ```

## 17.5 Timers

Timer函数..

``` GTimer* g_timer_new (void); void g_timer_destroy (GTimer *timer); void g_timer_start (GTimer *timer); void g_timer_stop (GTimer *timer); void g_timer_reset (GTimer *timer); gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds); ```

## 17.6 字串处理

``` GString* g_string_new (gchar *init); void g_string_free (GString *string, gint free_segment); GString* g_string_assign (GString *lval, gchar *rval); GString* g_string_truncate (GString *string, gint len); GString* g_string_append (GString *string, gchar *val); GString* g_string_append_c (GString *string, gchar c); GString* g_string_prepend (GString *string, gchar *val); GString* g_string_prepend_c (GString *string, gchar c); void g_string_sprintf (GString *string, gchar *fmt, ...); void g_string_sprintfa (GString *string, gchar *fmt, ...); ```

## 17.7 工具及除错函数

``` gchar* g_strdup (const gchar *str); ```

``` gchar* g_strerror (gint errnum); ```

``` program name:function that failed:file or further description:strerror ```

``` g_print("hello_world:open:%s:%s\n", filename, g_strerror(errno)); ```

``` void g_error (gchar *format, ...); ```

``` void g_warning (gchar *format, ...); ```

``` void g_message (gchar *format, ...); ```

``` void g_print (gchar *format, ...); ```

printf()的替代品.

``` gchar* g_strsignal (gint signum); ```