Boost logo

Boost Users :

Subject: [Boost-users] Writing custom allocator for use with extended boost vector
From: Olumide (50295_at_[hidden])
Date: 2014-12-30 22:10:21


I am considering using boost::container::vector as an alternative to
std::vector because std::vector moves when its capacity is exceeded.
This is a problem because I am using a lean stack-like allocator that
acquires a pool of memory from the heap and manages it my incrementing
or decrementing a pointer to the available memory; and automatically
moving the vector in the pool is a big no-no for several reasons chief
of which is that such moves invalidate the above pointer. My allocator
does not use a header block in order to delineate subsequent allocations.

This approach works because my application is recursive i.e. objects are
allocated and deallocated in a strict LIFO order. Furthermore
allocations are typically small (but not constant size) and and are
routinely smaller than the size of the canonical header block consisting
of a forward and backward pointer. To use such a header block would IMHO
be a waste.

I'd like to port this allocator to for use with boost::container::vector
but I'm not sure entirely sure how much of the
boost::container::allocator interface that I need to implement, or if
perchance there is already an allocator that does what I am trying to do.

Please advise.

Regards,

- Olumide


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net