I am trying to use the ReadUsingPointer Method described here to have a light spead binary reader for huge binary files.
However, the struct I am trying to pass to it contains strings. I was wondering how I could circumvent this and avoid the “cannot take the address of, get the size of, or declare a pointer to a managed type” message
I tried the following with no success so far (maybe having accessors to these fields is the problem?):
[MarshalAs(UnmanagedType.LPStr)]
string s;
I have to specify that these string fields are used after reading and are not assigned while reading the bytes, so I do not need them while reading (I could use an intermediary struct without these fields but for legacy issues I can’t do this).
So does your unmanaged structure contain arrays of characters? There really isn’t any practical way (that I know of) to model that on the managed side in a way that will be compatible with bulk copying since both strings and arrays are reference types on the managed side – if you declare a string in a .NET struct then the actual characters don’t really reside there – only a string pointer does. Same with arrays.