[Gdal-dev] ReadBlock in C#
sy at perkins.net
Tue Mar 27 19:05:06 EDT 2007
Simon Perkins wrote:
> Tamas Szekeres wrote:
>> However I have some doubts why would it be more efficient than calling
>> the ReadRaster/WriteRaster functions in exchange for the additional
>> problems may occur due to the possible errors when passing incorrect
>> In addition I cannot see how to avoid the extra array copy when
>> marsaling the code between the C and the C# memory. Or would you
>> possibly use the native pointer with the fixed statement inside an
>> unsafe block?
> We talked about having an unsafe version of Read/WriteRaster that
> avoided the array copy a while back. Did it make it in there?
Yes, there does seem to be a Band.ReadRaster() that takes an IntPtr to a
buffer. You can either use the fixed statement to get pointer to an
array, which you then pass as an IntPtr, or you can get an IntPtr
directly from structures like Bitmap using the BitmapData methods.
These avoid a copy. Note that if you invoke ReadRaster with buffers that
are the same size as the data block and you're not doing any type
conversion or rescaling, then ReadRaster will pretty much call the
underlying ReadBlock() directly anyway, so there's not really much
reason to expose it.
More information about the Gdal-dev