Если вы хотите создать непрерывный буфер полностью неструктурированных данных, рассмотрите возможность использования std::vector<char>
:
// Add an item to the end of the buffer, ignoring endian issues
template<class T>
addToVector(std::vector<char>& v, T t)
{
v.insert(v.end(), reinterpret_cast<char*>(&t), reinterpret_cast<char*>(&t+1));
}
// Add an item to end of the buffer, with consistent endianness
template<class T>
addToVectorEndian(std::vector<char>&v, T t)
{
for(int i = 0; i < sizeof(T); ++i) {
v.push_back(t);
t >>= 8; // Or, better: CHAR_BIT
}
}