
On Thu, Apr 24, 2008 at 8:29 AM, Mathias Gaunard < mathias.gaunard@ens-lyon.org> wrote:
shiwei xu wrote:
I only went through your article now.
First, this is not Garbage Collection at all. As a matter of fact, it does not collect garbage at any time.
Yes, it's not. Second, this is no innovation. This is a single-threaded stack allocator
with private instances. Basically the fastest thing ever, indeed.
I know that region allocators are no innovation. 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. Most allocators optimize allocating a lot of objects. If ONE allocator instance only allocates ONE object instance, they become slower than a normal new/delete allocation.
Stack allocation is simply the simplest algorithm and is extremely fast, yet - you waste lots of memory
Since you can define a lot of ScopeAlloc instances as you need, So It doesn't waste too much memory as normal region allocators. ScopeAlloc is useful. And I don't think it is all of C++ memory management. If you implement algorithms that are related to t (that is, how many time of the algorithm spent is unsure.), ScopeAlloc doesn't fit you directly.
- you can't really give the memory back to the OS
No. You can change limit of freelist size for each thread.
- you can only free in the reverse order you allocated in. For example, shared ownership is out of the question.
I don't think shared ownership is a requirement. It is only a memory management technique. Why don't Java programmers care such a question?
Also, you claimed this
{ std::auto_ptr<MyObj> obj(new MyObj); std::auto_ptr<AnotherObj> obj2(new AnotherObj); ... // use obj and obj2 to do something. }
was somewhat equivalent to this,
MyObj* obj = new MyObj; AnotherObj* obj2 = new AnotherObj; try { ... // use obj and obj2 to do something. } catch (...) { delete obj; delete obj2; throw; } delete obj; delete obj2;
Which is incorrect.
A possible equivalence would be:
{ MyObj* obj = new MyObj; try { AnotherObj* obj2 = new AnotherObj; } catch(...} { delete obj; throw; }
try { ... // use obj and obj2 to do something. } catch(...) { delete obj2; delete obj; throw; } delete obj2; delete obj; }
This certainly demonstrates that scope-bound resource management (aka RAII) certainly reduces the annoyance in writing exception-safe code.
Thanks for pointing out my mistakes. I revised my article now.