apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bojan Smojver <bo...@rexursive.com>
Subject Re: Changing the order of cleanup for some core objects
Date Wed, 23 Jul 2008 07:34:40 GMT
On Wed, 2008-07-23 at 09:23 +0200, Mladen Turk wrote:

> What do you mean by "hang a cleanup off it"?

See my example constructor.

> Socket cleanup is private function and cannot be modified.

Of course.

> constructor(res, pool) {
>     res->sock = socket_create(pool)
> }
> 
> destructor(res) {
> 
>      socket_shutdown(res->sock);
>      socket_close(res->sock);
> }

If we follow the design pattern Joe explained, we should not do the
above. Most definitely will segfault.

> What I can do is:
> 
> my_cleanup(res)
> {
>      socket_shutdown(res->sock);
>      socket_close(res->sock);

I guess the above are some kind of customized things (your own socket
shutdown and close routines). If not, pool cleanup will take care of
that (resource pool dies, socket is shut down), so no need for that.

>      res->sock = NULL

No need.

> }
> 
> constructor(res, pool) {
>     res->sock = socket_create(pool)
>     res->subpool = pool_create(pool)

You don't need that (pool creation) - you already have private pool for
this resource.

>     cleanup_register(res, res->subpool, my_cleanup);

Just register cleanup against the pool - it's just for this resource.

> }
> 
> destructor(res) {
>     if (res->sock) {
>        pool_cleanup_run(res->subpool, my_cleanup)

No need. This will run when resource is destroyed, because its pool is
destroyed.

> 
> So the whole bunch of code, two additional pools for each object
> (16K of wasted memory; multiply that by 1000 sockets), for what?

Actually, that's one additional pool per resource (automatically created
for you) and one extra for the list. About 8 MB of wasted space in your
example - quite a bit of a waste for sure. I cannot argue with that.

> A simple cleanup. I really don't understand the opposition
> for doing a things in a clean and safe way :(.

No so much the opposition, just another way to do it. Probably more in
line with the "design pattern" Joe described.

-- 
Bojan


Mime
View raw message