[.net] Pointer to Array
I need to speed up some memory copying by using Buffer.BlockCopy(), but I can't find a way to cast my *byte to the required byte[]. Any tips?
Buffer.BlockCopy() only accepts Arrays, and all I've got is a pointer. I thought Arrays and Pointers were similar enough to allow casting between them, but
byte* ptr = null;
byte[] array = (byte[])ptr;
doesn't compile.
byte* ptr = null;
byte[] array = (byte[])ptr;
doesn't compile.
You can try something like this:
byte test = 'a'; //Example bytebyte* ptr = &test; //Pointer to Example bytebyte array[0]; //Array of bytesarray[0] = *ptr; //Makes array[0] equal to the contents of ptrcout << array[0] << endl; //Prints contents of array[0]
But that would mean copying the data byte by byte manually, which is what I'm trying to avoid...
Quote:
byte* ptr = null;
byte[] array = (byte[])ptr;
Are you sure a cast is required at all? Have youy tried passing "ptr" directly?
Its been a while since i wrote C/C++ code but isnt an array always a pointer sort of? Just try what bakery2k1 adviced you to do.
if you have a byte[] varname, the expression 'varname' is a pointer to the first element of the array (if its allocated), so its type is byte*.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement