Note that there are some explanatory texts on larger screens.

plurals
  1. POProtobuf-net IsPacked=true for user defined structures
    primarykey
    data
    text
    <p>Is it currently possible to use IsPacked=true for user defined structures? If not, then is it planned in the future?</p> <p>I'm getting the following exception when I tried to apply that attribute to a field of the type ColorBGRA8[]: <em>System.InvalidOperationException : Only simple data-types can use packed encoding</em></p> <p>My scenario is as follows: I'm writing a game and have tons of blitable structures for various things such as colors, vectors, matrices, vertices, constant buffers. Their memory layout needs to be precisely defined at compile time in order to match for example the constant buffer layout from a shader (where fields generally? need to be aligned on a 16 byte boundary).</p> <p>I don't mean to waste anyone's time, but I couldn't find any recent information about this particular question.</p> <p><em><strong>Edit after it has been answered</em></strong></p> <p>I am currently testing a solution which uses protobuf-net for almost everything but large arrays of user defined, but blitable structures. All my fields of arrays of custom structures have been replaced by arrays of bytes, which can be packed. After protobuf-net is finished deserializing the data, I then use memcpy via p/invoke in order to be able to work with an array of custom structures again.</p> <p>The following numbers are from a test which serializes one instance containing one field of either the byte[] or ColorBGRA8[]. The <em>raw</em> test data is ~38MiB of data, e.g. 1000000 entries in the color array. Serialization was one in memory using MemoryStream.</p> <p>Writing<br> Platform.Copy + Protobuf: 51ms, Size: 38,15 MiB<br> Protobuf: 2093ms, Size: 109,45 MiB </p> <p>Reading<br> Platform.Copy + Protobuf: 43ms Protobuf: 2307ms </p> <p>The test shows that for <em>huge</em> arrays of more or less random data, a noticeable memory overhead can occur. This wouldn't have been such a big deal, if not for the (de)serialization times. I understand protobuf-net might not be designed for my extreme case, let alone optimized for it, but it is something I am not willing to accept.</p> <p>I think I will stick with this hybrid approach, as protobuf-net works extremely well for everything else.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload