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

l.jay Yuan pass86 at gmail.com
Tue May 22 16:56:20 UTC 2012


Thank you very much.So the design is specially for the web request.I
were going to learn the source and use for MMORPG game server.Game
clients's connection is transient.I want to improve the code.

2012/5/22 Vladimir Shebordaev <vshebordaev at mail.ru>:
> 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
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel



More information about the nginx-devel mailing list