23 Dec
2009
23 Dec
'09
12:40 a.m.
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