[gdal-dev] Commit r19248

Andrey Kiselev dron at ak4719.spb.edu
Tue Mar 30 06:27:29 EDT 2010


On Mon, Mar 29, 2010 at 11:23:08PM +0300, Ari Jolma wrote:
> I was wrong in saying that there are no "unnecessary" memory copies in  
> Perl. It seems that the raster data is copied to a buffer, from which it  
> is copied to another buffer maintained by Perl. I then have an extra  
> layer of Perl code to copy from that buffer to Perl scalar arrays for  
> ease of use. An optimization to do away one of the copies would be  
> useful. That would mean copying from the initial buffer directly into  
> Perl arrays within a typemap - I haven't done that because of the  
> complication of several datatypes. To change that would mean - not to  
> break existing code - defining a new set of read/write methods.
>
> Would that be compatible with what is wished for in the Python bindings?

Yes, that is what I tried to solve. In Python it looks like that:

%typemap(argout) (int *nLen, char **pBuf )
{
  /* %typemap(argout) (int *nLen, char **pBuf ) */
  Py_XDECREF($result);
%#if PY_VERSION_HEX >= 0x03000000
  $result = PyBytes_FromStringAndSize( *$2, *$1 );
%#else
  $result = PyString_FromStringAndSize( *$2, *$1 );
%#endif
}

PyString_FromStringAndSize() takes the array allocated in ReadRaster_internal()
function (see Band.i) and copies it into the string. The former array is being
deallocated after that. I would like to read directly in the final string
object. I think it could be done using the buffer API in recent Python
branches.

For now I have reverted back the problem commit.

Best regards,
Andrey

-- 
Andrey V. Kiselev


More information about the gdal-dev mailing list