Thursday, December 4, 2008

Memory Allocation

Memory Allocation: "g_new()

#define g_new(struct_type, n_structs)

Allocates n_structs elements of type struct_type. The returned pointer is cast to a pointer to the given type. If n_structs is 0 it returns NULL.

Since the returned pointer is already casted to the right type, it is normally unnecessary to cast it explicitly, and doing so might hide memory allocation errors.
struct_type : the type of the elements to allocate
n_structs : the number of elements to allocate
Returns : a pointer to the allocated memory, cast to a pointer to struct_type
g_new0()

#define g_new0(struct_type, n_structs)

Allocates n_structs elements of type struct_type, initialized to 0's. The returned pointer is cast to a pointer to the given type. If n_structs is 0 it returns NULL.

Since the returned pointer is already casted to the right type, it is normally unnecessary to cast it explicitly, and doing so might hide memory allocation errors.
struct_type : the type of the elements to allocate.
n_structs : the number of elements to allocate.
Returns : a pointer to the allocated memory, cast to a pointer to struct_type.
g_renew()

#define g_renew(struct_type, mem, n_structs)

Reallocates the memory pointed to by mem, so that it now has space for n_structs elements of type struct_type. It returns"

No comments:

Post a Comment

發表一下意見,互動一下唄!

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Adventure Book 2.0 Headline Animator

GoogleAd

funP Android 相關文章