Skip to content

How to convert complex struct into Span<byte>? And how about reverse? #72758

Answered by DaZombieKiller
Flithor asked this question in Q&A
Discussion options

You must be logged in to vote

You cannot treat a managed structure (one containing refs, classes, arrays, etc) as a sequence of bytes and write it to a file, because managed types are not blittable. Arrays, strings, etc are not stored inline in the structure, they are GC-tracked pointers to data on the managed heap. They will have no meaning once they are written to disk. I would suggest using an existing binary serialization framework when you have a complex scenario like this.

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Flithor
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants