Boost.Serialization and size of archive

Hi, Is there any means of obtaining how big my archive will be before actually serializing? Something like a special boost::archive that will count the size of what I'm serializing. I'm mainly concerned on allocating exactly the space I'll be needing for binary_oarchives. I guess I should follow the SA concept (since I'm trying to find the size before saving) but how can I know any extra overhead? Thanks

One can easily write a binary archive that simply counts the number of bytes that would be written Matthias

Ioannis Papadopoulos wrote:
Hi,
Is there any means of obtaining how big my archive will be before actually serializing? Something like a special boost::archive that will count the size of what I'm serializing. I'm mainly concerned on allocating exactly the space I'll be needing for binary_oarchives.
I guess I should follow the SA concept (since I'm trying to find the size before saving) but how can I know any extra overhead?
You could probably use boost.iostream library to create a sink that increments a size but doesnt' actually 'write' anything, then pass that to the oarchive's constructor. Be sure to use the same oarchive type that you will actually write to later. Jeff

you could way make a streambuffer which doesn't do anything other than count characters and make an archive based on that. robert Ramey Ioannis Papadopoulos wrote:
Hi,
Is there any means of obtaining how big my archive will be before actually serializing? Something like a special boost::archive that will count the size of what I'm serializing. I'm mainly concerned on allocating exactly the space I'll be needing for binary_oarchives.
I guess I should follow the SA concept (since I'm trying to find the size before saving) but how can I know any extra overhead?
Thanks

Ioannis Papadopoulos wrote:
Hi,
Is there any means of obtaining how big my archive will be before actually serializing? Something like a special boost::archive that will count the size of what I'm serializing. I'm mainly concerned on allocating exactly the space I'll be needing for binary_oarchives.
I guess I should follow the SA concept (since I'm trying to find the size before saving) but how can I know any extra overhead?
As others have mentioned, the only real way to do this is to effectively serialize twice. Once to count, once to do the the actual serialization. Out of curiosity, why do you need to do this? -- Sohail Somani http://uint32t.blogspot.com

Sohail Somani wrote:
Ioannis Papadopoulos wrote:
Hi,
Is there any means of obtaining how big my archive will be before actually serializing? Something like a special boost::archive that will count the size of what I'm serializing. I'm mainly concerned on allocating exactly the space I'll be needing for binary_oarchives.
I guess I should follow the SA concept (since I'm trying to find the size before saving) but how can I know any extra overhead?
As others have mentioned, the only real way to do this is to effectively serialize twice. Once to count, once to do the the actual serialization.
Out of curiosity, why do you need to do this?
FWIW, I used to use that tack when I needed a progress bar for long file save operations. Worked a treat. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

David Abrahams wrote:
Sohail Somani wrote:
Ioannis Papadopoulos wrote:
Hi,
Is there any means of obtaining how big my archive will be before actually serializing? Something like a special boost::archive that will count the size of what I'm serializing. I'm mainly concerned on allocating exactly the space I'll be needing for binary_oarchives.
I guess I should follow the SA concept (since I'm trying to find the size before saving) but how can I know any extra overhead? As others have mentioned, the only real way to do this is to effectively serialize twice. Once to count, once to do the the actual serialization.
Out of curiosity, why do you need to do this?
FWIW, I used to use that tack when I needed a progress bar for long file save operations. Worked a treat.
Who would have thought? An accurate progress bar! Crazy talk. Nice application though! -- Sohail Somani http://uint32t.blogspot.com

Sohail Somani wrote:
Ioannis Papadopoulos wrote:
Hi,
Is there any means of obtaining how big my archive will be before actually serializing? Something like a special boost::archive that will count the size of what I'm serializing. I'm mainly concerned on allocating exactly the space I'll be needing for binary_oarchives.
I guess I should follow the SA concept (since I'm trying to find the size before saving) but how can I know any extra overhead?
As others have mentioned, the only real way to do this is to effectively serialize twice. Once to count, once to do the the actual serialization.
Out of curiosity, why do you need to do this?
Yeah, I know it. I need it to serialize in a preallocated piece of memory and that's the only effective way.
participants (6)
-
David Abrahams
-
Ioannis Papadopoulos
-
Jeff Flinn
-
Matthias Troyer
-
Robert Ramey
-
Sohail Somani