[gdal-dev] Allocate large memory space with CPLMalloc(). Bug or not?
fazotron
alexzhdanov1003 at gmail.com
Thu Oct 1 12:18:33 PDT 2015
Hello!
Take a look on the following code:
*...
size_t w = 10000, h = 5000, d = 150;
size_t sz = w * h * d * sizeof(float); // ~27.94 Gb
float *volume = (float*)CPLMalloc(sz);
...*
In this case GDAL throws error in runtime: "ERROR 1: CPLMalloc(-664771072):
Silly size requested."
But I think that it's not silly, because such amount of free RAM is
available on my system. For example I can successfully allocate it calling
standart malloc().
I have opened CPLMalloc() source code and seen the following lines:
*void *CPLMalloc( size_t nSize )
...
if( long(nSize) < 0 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"CPLMalloc(%ld): Silly size requested.\n",
(long) nSize );
return NULL;
}
...*
In my case long( size_t nSize ) returns negative value and it leads to
error.
As far as I understand converting one integer type to another smaller
integer type (e.g. long long/size_t to long) is implementation-defined, so
it's not safe to use CPLMalloc() with 64-bit integers.
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Allocate-large-memory-space-with-CPLMalloc-Bug-or-not-tp5227443.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
More information about the gdal-dev
mailing list