On Jan 22, 2005, at 1:14 PM, Reid Spencer wrote:
My "Newbie Question" of this past Thursday has gone unanswered.

That's weird...

Begin forwarded message:

From: Ben Hyde <[EMAIL PROTECTED]>
Date: January 21, 2005 2:48:10 PM EST
To: Reid Spencer <[EMAIL PROTECTED]>
Subject: Re: Using APR << Newbie Question
X-Request-Pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x187BD68D
X-Url: http://enthusiasm.cozy.org/
X-Face: 8!qM\RM(~j4$R"ON<@7IZWkQHyuZz4"qxdae6*"1py2X$hFj';a/G_AO{Zi-SeiCqT|!wk |U!*'ZW$RJuP7D(H>XRx2:,#_K%g(i]sCz1Vqx#.bF6<JURWXZm'x.rK<"7bd|EGs/~v)r ,_Vp?P%q;f{=]lU=SJOoyO(@XblzxGUqB>Y|-|-(LKuNnD022-zAx8


Reid "Seriously in need of an APR tutorial" Spencer

You probably aren't unique in that regard :-)

I have an essay about pools around here someplace I really ought to make more public.

Here's a simple example. Pools are used to provide a very very cheap way to allocate
memory and an almost zero cost way to reclaim a batch of memory. So they are used
to provide scratch storage for activities; when the activity is finished the pool is cleared.
Or, they are used to provide all the storage for a large data structure and when you want
to destroy the data structure you just destroy the pool and poof the entire data structure
is reclaimed.




#include <stdlib.h>
#include <apr_pools.h>
#include <apr_uri.h>

/* Typically routines are handed a pool where they can
   allocate memory willy nilly, their caller reclaims
   all that memory from time to time.
*/

static void play_with_uri(apr_pool_t *p)
{
  apr_uri_t uri;

  apr_uri_parse(p, "http://example.com/foo.html",&uri);
  printf(" Scheme: %s\n", uri.scheme);
  printf(" Unparsed: %s\n", apr_uri_unparse(p, &uri, 0));
}


int main(int argc, char **argv) { apr_pool_t *process_pool; /* You always need one of these :-) */

apr_initialize();
atexit(apr_terminate);
apr_pool_create(&process_pool, NULL); /* No error handling in this program! */


  /* Create temporary pools for transient activities */
  {
    apr_pool_t *p;
    apr_pool_create(&p, process_pool); /* temp pool */

    play_with_uri(p);
    apr_pool_destroy(p);
  }

  return 0;
}





----
http://enthusiasm.cozy.org/   -- blog
tel:+1-781-240-2221  -- mobile, et.al.

---- http://enthusiasm.cozy.org/ -- blog tel:+1-781-240-2221 -- mobile, et.al.



Reply via email to