Reputation: 20004
Is it possible with flatbuffers
in C# to serialize objects to native (unmanaged) memory buffer?
So I want to do these steps:
I'm thinking either of some custom memory buffer allocator in C#, or of some way of transferring ownership of a memory buffer form C# to C++.
In general I want to avoid copying memory when sending data from C# to C++ and vice versa. I want this memory buffer to be shared between C# and C++.
How do I do that?
Upvotes: 2
Views: 1015
Reputation: 6074
No, the current FlatBuffers implementation is hard-coded to write to a regular byte array. You could copy this array to native memory afterwards, or like @pm100 says, pin it.
All serialization in FlatBuffers goes through an abstraction called the ByteBuffer
, so if you made an implementation of that for native memory, it could be used directly relatively easily.
Upvotes: 1
Reputation: 426
Yes, if you use C++/CLI. Basic data types such as bool, 32-bit int, short, etc are same. For other types check it out msclr::interop::marshal_as<>.
Similar post: C++/CLI Converting from System::String^ to std::string
Upvotes: 0