Re: please excuse very basic questions: gchar and g_free()



Yes, but the size of bytes you need is computed by ....

sizeof (type) * total

so I you needed 10 char array... you wouldn't want to assume that a
char is 2 bytes since different systems use different byte sizes...

so safely you would run    malloc( sizeof(char) * 10 )

calloc takes two parameters, and multiplies them for you automatically. 

calloc ( sizeof(char) , 10)... it will return a pointer to a block of
memory that has been zeroed out.

Hope this answers your questions.


On Thu, 25 Nov 2004 10:13:18 +0100 (CET), Jan-Marek Glogowski
<glogow fbihome de> wrote:
Hi

<snip a lot of questions about dynamic memory and gchar>

http://www.cs.cf.ac.uk/Dave/C/node11.html#SECTION001100000000000000000

#define g_new(struct_type, n_structs)           \
    ((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize)
(n_structs))))

malloc and free are about allocation a number of bytes - they don't care
about types.

HTH

Jan-Marek
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



-- 
Matt Jarjoura

"To announce that there must be no criticism of the 
president, or that we are to stand by the president,
right or wrong, is not only unpatriotic and servile, 
but is morally treasonable to the American public." 
- Theodore Roosevelt (1918)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]