Boost logo

Boost Users :

From: Clemens Buchacher (drizzd_at_[hidden])
Date: 2007-08-01 15:22:17


Hi,

Is it safe to do this?

using boost::array;

const size_t n;
void* p = new char[sizeof(T) * n];
array<T, n>* data = new(p) array<T, n>;

The reason I want to do this is that I have implemented my own memory
pool, so new char[...] would be replaced by my_pool<T>::allocate(n).

I don't want to use something like my_pool<array<T, n> >::allocate(1),
because then my allocator would have to align the allocated memory to the
total array size instead of just the size of its elements.

I suppose the safest solution would be an implementation of array with
dynamic memory and support for a standard allocator like, for example, a
one-dimensional multi_array or even multi_array_ref? I am concerned about
performance of those containers, however.

Regards,
Clemens


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