GLIB memory allocation



G'Day !

This is probably a really stupid/basic question, but here it goes.

I need to allocate room for a multi-dimensional array. Normally my declaration would be,

        float **array;

And I would allocate it with something like this (for row-major storage):

        array = (gfloat**) malloc((rows)*sizeof(gfloat*));
        for (i=0; i<rows; i++)
          array[i] = (gfloat*) malloc((columns)*sizeof(gfloat));

This would allow me to access my array as normal (ie array[i][j]). So far pretty basic C.

So my question is, what is the equivalent statements using GLIB's memory allocation routines ? Figured it out for vectors, but a brain fart keeps me from extending the logic to multi-dimensional arrays.

My other question is how would you free the same memory ?

BTW I am coding in GTK version 1.2.x, if it makes a difference.

Thanks for your help.

cheers,
Jim Parker




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