Hierarchical malloc

A

Alex Pankratov

I've been poking around Apache's code for the past week and
came across a simple, but an interesting idea while looking
at their memory pooling code. It is a generalization of malloc/
free interface, which allows organizing memory blocks into
naturally occuring hierarchies. An overview, brief documentation
and a reference implementation are available at:

http://www.cipherica.com/hhmalloc

Comments, critique, etc are most certainly welcome and appreciated.

thanks,
/alex
 
G

goose

Alex Pankratov said:
I've been poking around Apache's code for the past week and
came across a simple, but an interesting idea while looking
at their memory pooling code. It is a generalization of malloc/
free interface, which allows organizing memory blocks into
naturally occuring hierarchies. An overview, brief documentation
and a reference implementation are available at:

http://www.cipherica.com/hhmalloc

Comments, critique, etc are most certainly welcome and appreciated.

thanks,
/alex

---from hhmalloc.c---

void * hh_attach(void * ptr, void * owner)
{
struct hh_block * p = _hh_restore(ptr);
struct hh_block * q;
struct hh_block * q;
if (! p)
return 0;

_hh_lock();

/* check for loops */
for (q = owner; q; q = q->parent)
if (q == p)
{
_hh_unlock();
assert(0);
return 0;
}

/* reattach */
_hh_detach(p);

_hh_attach(p, _hh_restore(owner));

_hh_unlock();
}

what is hh_attach supposed to return ?

goose,
nice idea, dont know about the usefulness though, if I wanted
hierachies I'd use an OO language.
 
A

Alex Pankratov

goose said:
[snip]
what is hh_attach supposed to return ?

Original block pointer. This is to allow indicating
hh_attach() success vs failure due to the detected
loops in the hierarchy.
goose,
nice idea, dont know about the usefulness though, if I wanted
hierachies I'd use an OO language.

Sure it's an option; OO are not fit for some environments
though. I'm not promoting HH as a replacement for anything
that exists and does its job well. It's basically a neat and
*cheap* trick for adding garbage_collector-like behavior into
existing C codebase. Used it my code, and thought that it may
be useful for others.
 
A

Alex Pankratov

goose said:
> Alex Pankratov <[email protected]> wrote in message
> [snip]
> what is hh_attach supposed to return ?

Thanks for noting this. Original block pointer. This is
to allow indicating hh_attach() success vs failure due
to the detected loops in the hierarchy.
>
> goose,
> nice idea, dont know about the usefulness though, if I wanted
> hierachies I'd use an OO language.

Sure it's an option; OO are not fit for some environments
though. I'm not promoting HH as a replacement for anything
that exists and does its job well. It's basically a neat and
*cheap* trick for adding garbage_collector-like behavior into
existing C codebase. Used it my code, and thought that it may
be useful for others.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top