Memory management utilities



Hi,

I'm using glib2 in my own, non-gtk (i.e. non-gui) app/lib.  I find the
use of GMemChunk (and string chunks) somewhat inflexible, possibly
just because my imagination isn't sufficient.  If you compare it to
APR's (http://apr.apache.org) pool mechanism it seems that glib mem
chunks are specialized to memory administration for one type (ie
struct) because the allocatable atoms are size constrained when
creating the chunk.  APR's pool mechanism has also some weaknesses
(for example you can't free individual atoms which can lead to
problems comparable to mem leaks in long lived pools) but with
GMemChunk I find it hard to handle mem allocation for non-trivial
structs which contain pointers to other structs or 'char*'s.

Example:

struct my_struct {
        char *name;
        struct other_struct *crap;
};

If I want to provide a 'constructor' for that type I have to write
something like this:

struct my_struct *my_struct_constructor( struct GMemChunk
*my_struct_pool, struct GStringChunk *my_struct_name_pool, struct
GMemChunk *my_struct_crap_pool);

This is a little bit unelegant, I think.  Is there some idiomatic way
to handle this kind of situation?  I imagine that GTK has also often
the need for this.  Or is GObject the way to go?  I didn't look
seriously at it till now; any pointers for tutorials about GObject?

BTW which list is the place to propose patches for glib?  I would like
to propose something like

#define g_mem_chunk_get_atom_size(chunk) ...

to be able to do something like

struct my_struct *my_struct_constructor(struct GMemChnuk *ch) {
        g_assert(g_mem_get_atom_size(ch) >= sizeof(struct my_struct));
        ...
}


TIA,

andreas



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