apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sander Striker" <stri...@samba-tng.org>
Subject RE: apr_memory_system.c;apr_memory_system.h
Date Mon, 07 May 2001 18:43:02 GMT
Ok, included are the latest memory system sources.

Take a look at apr_tracking_memory_system.[ch] for
an example on how to implement a memory system.

The tracking memory system is a really trivial
one that does somewhat the thing that apr pool
does, only less efficient. It is provided as a
guide, but could ofcourse be used.

Ok, I didn't write a test program because I think
you guys could do that easily yourselves. The 
documentation in the code should be clear enough,
but there are a few issues that Luke would like to
add (regarding locking). Luke, please state them
here and I'm sure someone will copy them over in
the final source.

Usage example (lacks error checking):

  ...
  apr_memory_system_t *sms;
  ...
  apr_standard_memory_system_create(&sms);
  ...


  ...
  void *mem;

  mem = apr_memory_system_malloc(sms, 100);
  ...
  [ do something with the memory ]
  ...
  apr_memory_system_free(sms, mem);
  ...


  ...
  apr_memory_system_t *tms;
  ...
  apr_tracking_memory_system_create(&tms, sms);
  ...

  for (int n = 0; n < 100; n++)
  {
    mem = apr_memory_system_malloc(tms, 100);

    [ do something with the memory ]
  }

  /* done with all the memory in tms, 
   * no free'ing needed since its tracking.
   */
  apr_memory_system_destroy(tms); 

  [ do more alloc/free stuff with sms ]

  /* make sure everything is free'd first,
   * since the standard memory system doesn't do tracking 
   */
  apr_memory_system_destroy(sms); 


Hope this is clear enough, if not, ask me.

Oh, ofcourse this again shows that function names and possibly
type names are way too long. This was just done for clarity,
not for convenience. I'd suggest shortening them.



Sander

Mime
View raw message