The following code snippet is from The Official GNOME 2 Developer's Guide:
GMemChunk my_chunk;
my_chunk = g_mem_chunk_new("My Chunk",
42,
42*16,
G_ALLOC_AND_FREE);
gchar *data[50000];
gint i;
/* allocate 40,000 atoms */
for(i = 0; i < 40000; i++)
{
data[i] = g_mem_chunk_alloc(my_chunk);
}
Does this mean every atom is of 42 bytes, each "memory chunk" contains
4216 atoms, and40000/16=2500
memory chunks will be created when the above code is run?Why are they using gchar* here? Does an implicit cast from gpointer (void*) to gchar* take place when
data[i] = g_mem_chunk_alloc(my_chunk);
is run?If the above statement is true then each gchar* points to 42 bytes of memory. How do I access all the bytes of a particular atom, then? Will
data[7]+41
be a usable memory location?
When I try to compile the code gcc produces this error message:
error: storage size of ‘my_chunk’ isn’t known
What's wrong?