# H5DFill() and memory pointer

**URL:** <https://forum.hdfgroup.org/t/h5dfill-and-memory-pointer/11445>\
**Category:** HDF5 Library\
**Created:** [August 22, 2023, 3:43pm UTC](https://forum.hdfgroup.org/t/h5dfill-and-memory-pointer/11445 "2023-08-22T15:43:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://forum.hdfgroup.org/u/pierre)\
**Post date:** [August 22, 2023, 3:43pm UTC](https://forum.hdfgroup.org/t/h5dfill-and-memory-pointer/11445/1 "2023-08-22T15:43:14Z")

</div>

I don’t understand the `H5Dfill()` API. I can’t find any sample code, neither more detailed doc.

How is “buf” supposed to be used ? (`Pointer to the memory buffer containing the selection to be filled`)  
I don’t understand the concept of “memory buffer” when I am just trying to fill a whole dataset with a specific value. I am not aware of any mean to load a subset of the dataset in memory and get a pointer to it.

I can see that `H5Diterate()` also have such an unexpected “memory pointer” concept that I can’t find out how is is supposed to be used.

I must miss out something.

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [August 22, 2023, 5:51pm UTC](https://forum.hdfgroup.org/t/h5dfill-and-memory-pointer/11445/2 "2023-08-22T17:51:45Z")

</div>

```auto

herr_t H5Dfill(const void* fill, hid_t fill_type_id, void* buf, hid_t buf_type_id, hid_t space_id);

```

Given a memory buffer `buf` and a subset of elements, as described by a selection on `space_id`, the purpose of `H5Dfill` is to initialize each of the selected elements in the buffer with the fill value `fill` provided. (There might be a datatype conversion between `fill_type_id` and `buf_type_id`.)

For a simple example, take an uninitialized memory buffer large enough to hold `n` elements of size `s [byte]`. Let’s assume we have a dataspace of `n` elements, where every other element is selected. Calling `H5Dfill` with a fill value on this buffer will initialize every other element with a copy of that fill value. OK?

You cannot use this function with datasets in an HDF5 file. You would use a combination of `H5Pset_fill_value` and `H5Pset_fill_time` for that. However, you can, of course, `H5Dwrite` a buffer prepared by `H5Dfill` to a dataset.

OK?

G.

---

<div class="post-metadata">

**Author:** ![pierre](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://forum.hdfgroup.org/u/pierre)\
**Post date:** [August 23, 2023, 6:55am UTC](https://forum.hdfgroup.org/t/h5dfill-and-memory-pointer/11445/3 "2023-08-23T06:55:48Z")

</div>

> [@gheber](#):
>
> You cannot use this function with datasets in an HDF5 file. You would use a combination of `H5Pset_fill_value` and `H5Pset_fill_time` for that. However, you can, of course, `H5Dwrite` a buffer prepared by `H5Dfill` to a dataset.

Ok!  
I suggest a doc update to state that better, because even if there must be a good reason, it is surprising.
