[gdal-dev] Space Disk/Memory of Image

Brad Hards bradh at frogmouth.net
Tue May 9 02:09:46 PDT 2023


On Tuesday, 9 May 2023 6:47:39 PM AEST Elena Ruiz wrote:
> Hello, I need to know the disk size of an image, I calculate it using the
> following formula:
> 
> Disk size=( sizex*sizey*bits per pixel)/8 =memory size without compression
> 
> But when the image is compressed on disk it occupies less and the size in
> memory is much larger, is there some method in the C++ GDAL API, to obtain
> the size on disk, size on memory, or the compression factor? 

I think the math is fine for the size in memory (although depending on tiling, 
you might not have it all loaded).

For size on disk, the GDAL API probably isn't the best option. Why not use 
stat(2)/fstat(2)/lstat(2)? That will almost always be faster and at least as 
accurate than anything you can calculate.

Brad





More information about the gdal-dev mailing list