[redland-dev] Memory allocation in generate_id_handler

Dave Beckett dave.beckett at bristol.ac.uk
Thu Jun 24 16:19:54 BST 2004


On Thu, 24 Jun 2004 12:25:34 +0200, Jasper van de Gronde <th.v.d.gronde at hccnet.nl> wrote:

> I use a generate_id_handler in my application (I'm talking about 
> Raptor), which has to allocate some memory for the string it returns. 
> Now my question is how I am supposed to do this. Currently I just use 
> malloc as I traced to where the string got freed and saw it was freed by 
> free (seems sensible).

Yes, it's used internally and the parsers invoke free() when
via the RAPTOR_FREE macro when they are finished with the string.

> As I'm linking statically to raptor this doesn't present much of a 
> problem, but if I was to link dynamically to raptor this would most 
> likely cause problems (on Win32 at least, as the dll's don't - have to? 
> - share the same instance of the runtime library), at least that's how I 
> understand it (and that's what has given me quite a few problems in the 
> past, with other libraries).

Hmm.  This DLL feature is a bit bizarre!  A runtime in each DLL
sounds very odd, unless all DLLs are essentially parallel
processing.  But I digress.

> Am I overlooking something? On Win32 this could be solved by simply 
> adding a raptor_alloc_function or letting the user of the library free 
> the memory in some way (the module that allocates the memory should also 
> free it).

I would rather not abstract all the allocation functions in raptor
via another level of pointers, making all the code slower.  So the
solution I prefer is to allow your code to call a raptor memory
allocation function in your genid callback code.  I'd probably name
it raptor_alloc_memory to match raptor_free_memory (which already
exists) and just wrap the internal RAPTOR_MALLOC.

Prototype:
  void* raptor_alloc_memory(size_t size);

Just adding this now.

Dave



More information about the redland-dev mailing list