Faster Virtual Method Dispatch

James Dunne james.jdunne at gmail.com
Wed Apr 26 09:19:29 PDT 2006


BCS wrote:
> 
> [snip] I think the argument is that in any non trivial project, manually freeing
> all of the memory without any memory leaks or axing something to soon would
> require more overhead than using GC. The trade-off is not in the freeing time
> but in the can-I-free-this check.
> 

Not true.  A hierachical memory management system is great!  It sure 
beats reference counting, manual memory management, and conservative GC.

What you do is allocate some memory, but also provide a "parent" memory 
pointer to relate the new memory to.  When all is said and done you have 
a nice tree of related memory pointers (hopefully with just one root, 
provided you designed correctly).

To free some memory, simply walk all the branches of that node, freeing 
their memory, then free the original memory.  You can even get 
predictable destructors for objects this way.

I'm currently developing a project in C which uses this method.  I have 
it allocating lots of small blocks of memory to perform a job.  The 
total comes to 32KB.  When the program is finished I do one "free" call 
to the root structure and I get back ALL of my memory.  Not a single 
byte is leaked.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O 
M--@ V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e 
h>--->++ r+++ y+++
------END GEEK CODE BLOCK------

James Dunne



More information about the Digitalmars-d mailing list