niXman / yas

Yet Another Serialization
731 stars 95 forks source link

a save function to construct the last object in advance #144

Closed Darwinnpos closed 1 year ago

Darwinnpos commented 1 year ago

We want the binary data to be in shared memory when the serialization of the Request or Response completes. Instead of serializing into a non-shared-memory buffer and copying it into a shared-memory buffer.

Whether it is possible to provide a save function to construct the last object in advance, the last serialization is over, and the data exists in the target location.

niXman commented 1 year ago

you can just construct a ostream for your provided ptr and size:

void *shared_ptr = ...
size_t shared_size = ...

yas::mem_ostream os{shared_ptr, shared_size};
yas::binary_oarchive<yas::mem_ostream> oa{os};
oa & YAS_OBJECT(...);
Darwinnpos commented 1 year ago

How do you estimate the memory of the target object? Or it can be roughly estimated.

niXman commented 1 year ago

yes, you must determine/specify the maximum possible size of the required memory for a specific object.

also, you can use yas::count_ostream: https://github.com/niXman/yas/blob/7c5ced1d940ddc6826cf537468e65ea1f592bfe4/include/yas/serialize.hpp#L310

Darwinnpos commented 1 year ago

You mean the space needed for serialization can be calculated using this without actual serialization happening?

niXman commented 1 year ago

correct!

Darwinnpos commented 1 year ago

If I have a custom class that defines a custom serialization function, do I need to customize the serialization space calculation method?

niXman commented 1 year ago

could you please provide the code you are talking about? I'm unsure I understood the question...