# Problem with getting hdf5 file size

**URL:** <https://forum.hdfgroup.org/t/problem-with-getting-hdf5-file-size/2170>\
**Category:** Hdf-forum archives\
**Created:** [May 4, 2011, 8:13am UTC](https://forum.hdfgroup.org/t/problem-with-getting-hdf5-file-size/2170 "2011-05-04T08:13:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sentenac\_Daniel](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@Sentenac\_Daniel](https://forum.hdfgroup.org/u/Sentenac_Daniel)\
**Post date:** [May 4, 2011, 8:13am UTC](https://forum.hdfgroup.org/t/problem-with-getting-hdf5-file-size/2170/1 "2011-05-04T08:13:16Z")

</div>

Hello,  
I am currently doing a very small test to retreive the size of a just created HDF5 file using the function  
H5Fget\_filesize \<[http://www.hdfgroup.org/HDF5/doc/RM/RM\_H5F.html#File-GetFilesize](http://www.hdfgroup.org/HDF5/doc/RM/RM_H5F.html#File-GetFilesize)\> and cannot understand why the size returned is actually different from the real one.

Here is the simple example piece of code:

hsize\_t size;  
hid\_t file\_id = H5Fcreate("file.hdf5", H5F\_ACC\_TRUNC, H5P\_DEFAULT, H5P\_DEFAULT);  
H5Fget\_filesize( file\_id, &size );

The real size of the file appears to be 800 bytes, while the size returned fromH5Fget\_filesizeis 2144 bytes.

I would like to use the function H5Fget\_vfd\_handle to get a (char\*) buffer copy of the file. Can someone help me to do that correctly ?

Many thanks,

Daniel Sentenac

---

<div class="post-metadata">

**Author:** ![Quincey\_Koziol](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/q/dbc845/32.png) [@Quincey\_Koziol](https://forum.hdfgroup.org/u/Quincey_Koziol)\
**Post date:** [May 4, 2011, 4:16pm UTC](https://forum.hdfgroup.org/t/problem-with-getting-hdf5-file-size/2170/2 "2011-05-04T16:16:29Z")

</div>

Hi Daniel,

> Hello,  
> I am currently doing a very small test to retreive the size of a just created HDF5 file using the function  
> H5Fget\_filesize and cannot understand why the size returned is actually different from the real one.
> 
> Here is the simple example piece of code:
> 
> hsize\_t size;  
> hid\_t file\_id = H5Fcreate("file.hdf5", H5F\_ACC\_TRUNC, H5P\_DEFAULT, H5P\_DEFAULT);  
> H5Fget\_filesize( file\_id, &size );
> 
> The real size of the file appears to be 800 bytes, while the size returned fromH5Fget\_filesize is 2144 bytes.

&nbsp;&nbsp;The library allocates a 2KB buffer to sub-allocate metadata from (in addition to the ~100 byte superblock for the file), but then truncates the file's size down to the actual amount of data used in the file, when the file is closed.

> I would like to use the function H5Fget\_vfd\_handle to get a (char\*) buffer copy of the file. Can someone help me to do that correctly ?

&nbsp;&nbsp;I would recommend against this sort of mucking with the bytes - the HDF5 library does a lot of work behind the scenes and you probably won't get a coherent picture of the file by just looking at the bytes.

&nbsp;&nbsp;That said, why do you want to do this? Possibly the "core" VFD (H5Pset\_fapl\_core) would meet your needs?

&nbsp;&nbsp;Quincey

> **···**
>
> On May 4, 2011, at 3:13 AM, Sentenac Daniel wrote:
