Boost logo

Boost :

From: shiwei xu (xushiweizh_at_[hidden])
Date: 2008-04-30 14:23:48


Documentation: http://cpp.winxgui.com/boost-gc-alloc.

On Wed, Apr 30, 2008 at 9:47 AM, shiwei xu <xushiweizh_at_[hidden]> wrote:

> Hello all,
>
> Recently I write a new class named "boost::gc_alloc" (see
> http://svn.boost.org/trac/boost/browser/sandbox/memory/boost/memory/gc_alloc.hpp).
> Here is its specification:
>
> class gc_alloc
> {
> public:
> gc_alloc(); // same as: gc_alloc(tls_block_pool::instance());
> gc_alloc(block_pool& pool); // initialize by given a pool instance
> gc_alloc(gc_alloc& a); // initialize by given a indirect pool instance
> ~gc_alloc(); // clear
>
> void* allocate(size_t cb); // allocate memory without cleanup function
> void* allocate(size_t cb, destructor_t fun); // allocate memory with
> cleanup function
>
> void deallocate(void* p, size_t cb);
>
> template <class Type>
> void destroy(Type* obj);
>
> template <class Type>
> void destroyArray(Type* array, szie_t count);
>
> void clear(); // cleanup and release all memory allocated by the
> allocator
>
> void swap(gc_alloc& o); // swap two instances
> };
>
> Comparing with boost::scope_alloc (
> http://svn.boost.org/trac/boost/browser/sandbox/memory/boost/memory/scoped_alloc.hpp),
> It appends these methods:
>
> {
> void deallocate(void* p, size_t cb);
>
> template <class Type>
> void destroy(Type* obj);
>
> template <class Type>
> void destroyArray(Type* array, szie_t count);
> }
>
> Yes, it allows you to delete objects manually. But this is OPTIONAL, not a
> MUST. You don't need to delete objects, if you don't want or forget to do.
>
> However, I have some additional NOTES:
>
> 1. boost::auto_alloc (its old name is "AutoFreeAlloc") and
> boost::scoped_alloc (its old name is "ScopeAlloc") had been implemented for
> four years (from 2004). And they are widely used and tested. They are proved
> in practice.
>
> 2. boost::gc_alloc was implemented yesterday (just a pre-alpha version).
> It is complexer than boost::auto_alloc and boost::scoped_alloc. Is it
> useful? Maybe, but it needs to be proved itself.
>
> If you are interested in it, refer the source code:
> http://svn.boost.org/trac/boost/browser/sandbox/memory/boost/memory/gc_alloc.hpp
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk