apr_pool_t
While browsing the Subversion doc.s they had a code example of using the apr_pool_t. apr_pool_t is part of the the Apache Portable Runtime, which Subversion uses. The thing that struck me was how similar the mechanics of apr_pool_t are to NSAutoreleasePool.
The difference between these two mechanisms is that NSAutoreleasePool also allows for reference counting, whereas the apr_pool_t is a strict alloc/free allocator. The apr_pool_t interface is more explicit, whereas NSAutoreleasePool does a lot of things for you, such as global tracking of pools instead of constantly passing around the pool as an argument.
apr_status_t apr_pool_create (apr_pool_t **newpool, apr_pool_t *parent)
This creates a new pool and links it onto the parent pool. +[NSAutoreleasePool new] does the same thing, except that it implicitly links it to the parent instead of the programmer needing to explicitly specify a parent.
void *apr_palloc (apr_pool_t *p, apr_size_t size)
This allocates memory from a pool. NSObjects are not allocated from a pool, rather they are placed into an NSAutoreleasePool via -[NSObject autorelease].
void apr_pool_destroy(apr_pool_t *p)
This frees all memory allocated in a pool, all of its subpools and the pool itself. -[NSAutoreleasePool release] (or dealloc to be specific) behaves the same way.
APR pool function reference
Given how similar these two mechanisms are, I have to wonder if it could be subjected to the NSAutoreleasePool patent?

0 Comments:
Post a Comment
<< Home