Boost logo

Boost Users :

Subject: [Boost-users] alignment question
From: Slawomir Lisznianski (slisznia_at_[hidden])
Date: 2009-12-22 19:40:39


I'm having trouble implementing properly aligned storage. The
following example shows conceptually what I'm trying to do, but it's
NOT a correct way of doing it.

template <typename T>
struct envelope
{
  size_t len = sizeof(T);
  // <--- compiler may pad here, hence this doesn't work...
  T body;
};

So, given an arbitrary type T, we want to create an envelope that will
have the size of T immediately before it, with no padding between len
and body.

The user would then be able to:

   envelope<MyStruct> env;

   env.body.x = ...

   send(env);

I'm curious if anyone has run into something similar and have a clean
solution. Our code currently has to defer to temporary buffers and
memcpy'ing data back to it.

Thanks,
Slaw


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