apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Kew <n...@webthing.com>
Subject apr pool realloc?
Date Sat, 24 Jul 2004 09:06:17 GMT

Is there some fundamental reason why there's no apr_prealloc()?

I find myself working around this with constructs like:

typedef struct {
  char* buf ;		/* buffer */
  size_t offset ;	/* bytes used */
  size_t avail ;	/* bytes allocated */
} my_realloc_ctx ;

static void my_realloc(apr_pool_t* pool, my_realloc_ctx* ctx, size_t len)
{
  char* newbuf ;
  while ( len > ctx->avail ) {
    ctx->avail += BUFSZ ;
  }
  newbuf = realloc(ctx->buf, ctx->avail) ;
  if ( newbuf != ctx->buf ) {
    if ( ctx->buf )
        apr_pool_cleanup_kill(pool, ctx->buf, (void*)free) ;
    apr_pool_cleanup_register(pool, newbuf,
        (void*)free, apr_pool_cleanup_null);
    ctx->buf = newbuf ;
  }
}

But I can't help thinking this should be
  (a) standardised.
  (b) optimised to work with pools.


-- 
Nick Kew

Mime
View raw message