apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yann ...@bee-ware.net>
Subject Opaque apr_pool_t structure
Date Wed, 04 Jun 2008 13:20:25 GMT

I'm making a piece of software that recycles apr_sockets in sockets-pools.

Each socket is allocated and created on its own pool (not a subpool, or exactly a subpool
of the internal global pool 
I've read on svn programming pages that it is not recommanded to do this, but I find it very
usefull, that's the power 
of pools, IMHO.

Anyway, to make the things clean, I need a way to attach/detach pools to/from others, whether
the socket belongs to the 
socket-pool's pool or to the user's one.

As the apr_pool_join() function is a noop (and I don't knwow if that's its purpose anyway),
I used the 
apr_pool_cleanup_register()ing / apr_pool_cleanup_kill()ing mechanism to attach / detach pools
between them.

I create a small new API with my pools based on the APR ones, where I can attach/detach pools,
as I said, but also 
malloc() and realloc() memories attached to a pool (with the same registering mechanism).

My pool struct is like :

struct my_pool_t {
  apr_pool_t pool;
  apr_pool_t *owner;

And the functions :

apr_status_t my_pool_create(my_pool_t **pool, void *owner);
apr_status_t my_pool_attach(my_pool_t *pool, void *owner);
apr_status_t my_pool_detach(my_pool_t *pool);

apr_status_t my_pmalloc(void *pool, apr_size_t size);
apr_status_t my_pzalloc(void *pool, apr_size_t size);
apr_status_t my_prealloc(void *pool, void *ptr, apr_size_t size);
void my_pfree(void *pool, void *ptr);

As you can see with the first element of the struct which is an APR pool and 'void*' types
used in functions, I expect 
the functions to be "compatible" with the APR ones, that is I can use my_pool_t and apr_pool_t
pools indistinctly with 
them (where the type is void*) ...

My problem is that I can't initialize my_pool because I haven't got the sizeof(apr_pool_t),
an opaque structure ...

I understand the advantages of opaque types, but is there a way an apr_pool_sizeof() function
be added (and exported) in 
the APR, simply like :

APR_DECLARE(apr_size_t) apr_pool_sizeof(void)
  /* maybe the aligned SIZEOF_POOL_T should be used */
  return sizeof(apr_pool_t);

With it, I could at least do :
  apr_pool_create(&p, NULL);
  memcpy(my_pool->pool, p, apr_pool_sizeof())

Or should I consider using my_p*() functions strictly with my_pools ?

Thanks for your advices, answers.

View raw message