In C #, I need to write T [] to a stream, ideally without any additional buffers. I have dynamic code that converts T [] (where T is a structure without objects) to void * and commits it to memory, and this works fine. When the stream was a file, I could use my own Windows API to pass void * directly, but now I need to write a generic Stream object that accepts byte [].
Question: Can anyone suggest a hacked way to create a dummy array object that does not actually have heap allocations, but points to an existing (and fixed) heap location?
This is the pseudo code I need:
void Write(Stream stream, T[] buffer)
{
fixed( void* ptr = &buffer )
{
int typeSize = sizeof(T);
byte[] dummy = (byte[]) ptr;
stream.Write( dummy, 0, buffer.Length*typeSize );
}
}
Update:
, fixed(void* ptr=&buffer) . [], , , .
?
, [] . () T [], [] , T []. , T [] , [], [] .
@Microsoft Connect
, , MS .