Rule of thumb: size of boost archive in relation t

2019-09-16 15:41发布

问题:

For reasons that I will gloss over, I need to set aside space of a fixed size, and then use boost serialization to store an object there. The choice of archive format is arbitrary, and portability is not a concern.

The class is fairly complex (members include fundamental types, arrays, pointers, and child classes) and guaranteed to grow over time.

Does anyone have worthwhile sizing guestimates they trust? Space is important, but it's not at a premium. I'm looking for relatively simple answers like "2*(sizeof X) for binary" or "4 * number of members + 3*sizeof(X) if you like text archives".

Thanks

回答1:

No responses, so here's what experimentation showed.

From our application, one class had ~190 members, sizeof(A) = 12704. That's a little shy of actual total size due to pointers.

Size of binary_oarchive was 13981 and text_oarchive was 21237. This was for default traits, and an archive with a half-dozen derived types registered too.

So, I'm going to use 2*sizeof(A) as an upper bound for a text archive, and maybe 1.5* for a binary.