[gdal-dev] CPLCalloc() used for small memory allocations. And for big ones?
Laurențiu Nicola
lnicola at dend.ro
Wed Feb 14 01:00:59 PST 2024
Hi,
On Wed, Feb 14, 2024, at 10:53, Abel Pau via gdal-dev wrote:
> Hi,
>
> I am currently working on a driver and have been utilizing CPL_calloc(). However, when attempting to pass the Actions, I encounter errors such as:
>
> warning C4244: 'function': conversion from 'MM_INTERNAL_FID' to 'size_t', possible loss of data
>
> This issue can be addressed by casting 'MM_INTERNAL_FID' (which is a GUInt64, essentially an unsigned long long) to 'size_t' (also essentially an unsigned long long). So, utilizing a cast is not problematic in this context.
>
The warning makes sense on 32-bit platforms, where that cast will be problematic.
However, while I didn't check what MM_INTERNAL_FID is, it doesn't sound like something calloc() would take.
> However, I noticed in the function description it states "used for small memory allocations," which prompts me to inquire if there is an alternative calloc function for larger memory allocations
>
"Small" probably means "infallible" here. If you want a fallible allocation (which you're supposed to handle), you can use VSICalloc(), VSIMalloc() etc.
Laurentiu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240214/7936fe7d/attachment.htm>
More information about the gdal-dev
mailing list