G
Guest
Hi All,
I'm stuck whit an issue I can't seem to resolve in C#:
I have an arry of bytes which I would like to "recast" to an array of
structs with an Explicit layout. I tried the Buffer.BlockCopy method, but
that one complains my struct is not a primitive type.
Any Suggestions ?
In detail:
my struct contains an int and a byte (so nothing special like arrays or so
;-), you can maybe best compare it with a point structure)
The array of bytes is... just an arry of bytes.
Ideally what I would like to do is assign the address of the last one to the
address of the first one. But C# doesn't like that anymore (?).
So I tried Buffer.BlockCopy, but as stated before that doesn't seem to work
because my struct is not a primitive type.
So Plan B. Using unsafe code and a fixed statement: I was able to iterate
through my byte array and cast/copy every struct item one by one. Altough it
did work, I don't really like this solution as it is consuming quite some
time (large array) while the memory contents are just identical for both.
Can somebody help me out on this.
I'm stuck whit an issue I can't seem to resolve in C#:
I have an arry of bytes which I would like to "recast" to an array of
structs with an Explicit layout. I tried the Buffer.BlockCopy method, but
that one complains my struct is not a primitive type.
Any Suggestions ?
In detail:
my struct contains an int and a byte (so nothing special like arrays or so
;-), you can maybe best compare it with a point structure)
The array of bytes is... just an arry of bytes.
Ideally what I would like to do is assign the address of the last one to the
address of the first one. But C# doesn't like that anymore (?).
So I tried Buffer.BlockCopy, but as stated before that doesn't seem to work
because my struct is not a primitive type.
So Plan B. Using unsafe code and a fixed statement: I was able to iterate
through my byte array and cast/copy every struct item one by one. Altough it
did work, I don't really like this solution as it is consuming quite some
time (large array) while the memory contents are just identical for both.
Can somebody help me out on this.