Re: C++ Memory Management Innovation: GC Allocator
"xushiwei" <xushiweizh@gmail.com> wrote in message
news:937d3306-48cd-4907-a984-99bf16a253b0@w4g2000prd.googlegroups.com...
{ Please note that top-posting is discouraged in this group. -mod }
These days I spent a lot of time researching Boehm GC, Hoard/
HeapLayers/reaps, streamflow, dlmalloc, etc.
Yes, "GC Allocator" is a region allocator. It's no innovation.
Here is a very crude dynamic region allocator I did for C++:
http://groups.google.com/group/comp.lang.c++/browse_frm/thread/68bdc76f9792de1f
it allows calls to free, however it just ends up decrementing a counter.
When the count drops to zero, it resets the entire region offset. I need to
add a reset function to the public interface. That way, no explicit calls to
free are needed. You can do something like:
void foo(int count) {
for (; count > 0; --count) {
::operator new((i + 1) * 16);
}
}
int main() {
int i;
for (i = 1 ;; ++i) {
foo(i % 1024);
thread_reset(); // resets threads region allocator
}
return 0;
}
But:
This (ScopeAlloc) is not a normal region allocator. All ScopeAlloc
instances in the same thread share their freelist. This makes you can
define a lot of ScopeAlloc instances (depends your needs). You even
can define a ScopeAlloc instance for each allocation.
I am interested in increasing the granularity of region allocators. I need
to look at your source-code when I get some time.
[...]
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]