Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-28 15:47:33

----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>

> The current alignment solutions don't work in their current form, f.ex.
> aligned_storage<> needs the type beforehand.
> But wouldn't it be possible to implement (using aligned_storage<> as a
> starting point)
> template<class T> (T|void) * placement_allocate(unsigned char *,
> std::size_t);
> which then could be used by function<>:
> operator= (F f)
> {
> if(void * p = placement_allocate<F>(small_string_buffer, 16))
> {
> new(p) F(f);
> }
> else
> {
> // new F(f)
> }
> }

I need something very much like this for Boost.Python at the moment. What I
actually need looks more like this:

    I give the library some arbitrary type T and an object u of POD type
    U guaranteed to be sized/aligned so it can store a void*

    The library gives me back a pointer to storage in which I can do
    a placement-new of T. If possible, this storage is inside of u,
    otherwise, it's dynamically allocated.

    Another function can be used to free any such data.

I /think/ I need the ability to do placement-new, but it might be OK if the
library wrapped up the possible allocationi and construction. I'd rather
have the low-level facility at my disposal, though. That could help me
control when exceptions get thrown, for example if T had a non-throwing


Boost list run by bdawes at, gregod at, cpdaniel at, john at