You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hopefully useful for you!
Originally, if you're using std::vector as a serialize field, you must get memory copying, it's annoying.
And for some cases (game engine assets etc.) you definitely don't want any copying occured.
and if you would like to free the copied vector memory, it's typically hard in C++, because standard not say anything about how compliers should free the memory.
in my cases, a 70mb asset file, deserialize it directly eat my over 120mb memory, it's unacceptable, it can direcly use original file buffer.
So I dive into BufferAdapter and Extension, I found it actually very easy to eliminate it copying behavior.
The only things you need, is a custom adapter and an extension.
with caution : There is only be single alignment value available for all the noncopyable buffers(otherwise alignment value is multiple of others buffer like 32, 16, 8, 4), this might need some safety improvements(currently it's allow each buffer to say a wanted alignment)
The deserialization buffer(your passed into deserialize), MUST BE ALIGNED AS SAME AS noncopyable buffer, otherwise nothing will actually aligned.
I'm glad it worked for you and thanks for sharing! BTW, did you looked at @victorstewart#120, maybe it could make things for you even simpler?
Okay, It's do make things simpler, but it's do modified the source code. I think copying behavior should only be decided by user. Because some data is no need to avoid copying, and user may free the buffer just after deserialization(causing the field being invalid).
In my project, game engine asset pipeline, some binary blob data(textures, audio streams etc.) use original buffer, but for serializable fields they still copying.
My suggestion is, maybe you can provide a no copying read function in default input adapter, and simply make an built-in extension and let user decide.
Diarica
changed the title
I wrote an extension you can now deserialize buffer without any copying.
[UPDATED] with alignment. I wrote an extension you can now deserialize buffer without any copying.
Feb 11, 2025
Hopefully useful for you!
Originally, if you're using std::vector as a serialize field, you must get memory copying, it's annoying.
And for some cases (game engine assets etc.) you definitely don't want any copying occured.
and if you would like to free the copied vector memory, it's typically hard in C++, because standard not say anything about how compliers should free the memory.
in my cases, a 70mb asset file, deserialize it directly eat my over 120mb memory, it's unacceptable, it can direcly use original file buffer.
So I dive into BufferAdapter and Extension, I found it actually very easy to eliminate it copying behavior.
The only things you need, is a custom adapter and an extension.
with caution : There is only be single alignment value available for all the noncopyable buffers(otherwise alignment value is multiple of others buffer like 32, 16, 8, 4), this might need some safety improvements(currently it's allow each buffer to say a wanted alignment)
The deserialization buffer(your passed into deserialize), MUST BE ALIGNED AS SAME AS noncopyable buffer, otherwise nothing will actually aligned.
Usage :
The text was updated successfully, but these errors were encountered: