when ngx_array_t allocate a new array, why not ngx_pfree pre a->elts?

Vladimir Shebordaev vshebordaev at mail.ru
Tue May 22 15:51:11 UTC 2012


Hi!

2012/5/22 l.jay Yuan <pass86 at gmail.com>:
> when ngx_array_t allocate a new array, why not ngx_pfree pre a->elts?
>

Well, it seems to be a generic design decision. If you allocate a
dynamic object from the pool, you do it for speed, so, it is the most
likely relevant to the current request processing and supposed to be
destroyed right after that. It is done all at once when you
explicitely destroy the pool, either the objects  are allocated from
one of the server pools that only persist during the current request
processing.  Since there is no need in partial memory reclamaition, it
is faster to just allocate the memory anew.

> btw: ngx_pfree only free large memory, so I can not use ngx_pool_t everywhere...
>

If you do need the objects that would persist through different
request processing and the server reloading, you might want to use
ngx_slab_pool_t on some shared memory region. As far as I can recall
at the moment, nginx slab allocator provides necessary reclamaition
facilities.

--
Regards,
Vladimir



More information about the nginx-devel mailing list