Boost logo

Boost Users :

From: Michal Kandulski (Michal.Kandulski_at_[hidden])
Date: 2005-08-05 14:07:06


I'd like to implement a pimpl, pointing to a stack "allocated" buffer
by means of palcement new/destroy.

There would be no problem but there are alignment issues.

What really I need is:
- a way to check by te means of Boost wheater that an object of class
   X can be placed (with placement new) in a buffer of given adress
   and size:
- a way of getting a pointer to X (within the buffer) where the
   object could be paced

// file.hpp:

struct X


   struct Impl;
   const static int max_size = 100;
   Impl* m_pimpl;
   char m_impl_buffer[max_size];
   bool m_on_stack;

// file.cpp:

#include "file.hpp"

struct X::Impl
   // members

   m_on_stack = value_of(max_size is big enough for an object of X);
   if (m_on_stack)
     m_pimpl = new (m_impl_buffer)Impl; // any alignment stuff here???
     m_pimpl = new Impl;

   if (m_on_stack)
     delete m_pimpl;

I'll be gratefull for any help,


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at