How to store char (byte) buffers into a vector?

I have some char (byte) buffers and I want to store them into a vector
How have I to declare the vector ?
Basically I want to do a 'pusback' something like this :

char mybuff = char[65536];
myvectorofbuffs.pushback(mybuff);

And... later, if I have 4 buffers, can I get the whole data using vector.getallocator ?

Thanks

I suppose you could struct Buffer{ char data[65536]; }; and then std::vector<Buffer> v;. I don't think it is possible without a struct.
As for get_allocator, I'm not sure. I never used that.. And a quick glance at the reference didn't reveal any way to do that..
Though (char*)&myvector[0] should work. (however if you ever change the size of your buffer, be aware of memory padding).
Thanks, hamsterman.
I'm going to re-ask my question into a new topic.
Thanks again.
The allocator is an object responsible for providing memory to the vector class whenever it requires memory. This usually happens when the vector size changes. It has nothing to do with the data itself, unless you are picky and bring up the existence of the Construct() method.

In short, the allocator is not what you want. But a vector is in itself a buffer.

1
2
3
4
vector<char> myBuffer;
myBuffer.reserve(65536); //voilá:  A buffer of 64KB.
char *theBuffer = &myBuffer[0]; // A good ol' pointer to the buffer inside the vector.
//But you also can traverse the buffer with iterators. 
Topic archived. No new replies allowed.