Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-07-30 13:36:02


> The most straightforward way to implement it is to have the ptr<> have two
> pointers, similar to shared_ptr<>. Only instead of allocating the count
via
> "new int", allocate it from a pool.

Sorry I missed your point here. I understand your solution but I prefer
operator new (size_t, xmm) since sizeof(ptr<int>) == sizeof(int *).

> This is essentially what Dave did. A
> pool allocator for T (e.g., int) works by:
> 1) Allocating space for an array of T.
> 2) Keeping a "free list" that actually exists inside the space for this
> array of T.
> 3) Responding to an allocation request for a single T by returning the
> first element of the free list.
> 4) Responding to a deallocation request for a single T by adding it onto
> the front of the free list.
>
> As you can see, once the first allocation is made, all the pool
"allocation"
> and "deallocation"s are just some fast pointer operations. It gets a bit
> more complex when the free list is empty or if you want to free memory
back
> to the system, but a pool allocator can still provide amortized constant
> time.

Philippe A. Bouchard


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