# Help with array of compound type

**URL:** <https://forum.hdfgroup.org/t/help-with-array-of-compound-type/12811>\
**Category:** HDF5 Library\
**Created:** [November 20, 2024, 10:10pm UTC](https://forum.hdfgroup.org/t/help-with-array-of-compound-type/12811 "2024-11-20T22:10:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince.gibson](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/v/e68b1a/32.png) [@vince.gibson](https://forum.hdfgroup.org/u/vince.gibson)\
**Post date:** [November 20, 2024, 10:10pm UTC](https://forum.hdfgroup.org/t/help-with-array-of-compound-type/12811/1 "2024-11-20T22:10:44Z")

</div>

I am using HDF5 in C# via HDF.PInvoke.1.10. I have an array of a compound type that I wish to add to an encompassing compound type. When I get the size of the array type to add it to the encompassing compound type, it returns what appears to be a invalid pointer location.

hsize\_t[] max\_dims = { H5S.UNLIMITED };  
hid\_t header\_array = H5T.array\_create(\_header\_kvt, 1, max\_dims);  
H5T.get\_size(header\_array);

Returns:  
0xffffffffffffffe0

Thanks,  
Vince

---

<div class="post-metadata">

**Author:** ![vince.gibson](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/v/e68b1a/32.png) [@vince.gibson](https://forum.hdfgroup.org/u/vince.gibson)\
**Post date:** [November 21, 2024, 3:51pm UTC](https://forum.hdfgroup.org/t/help-with-array-of-compound-type/12811/2 "2024-11-21T15:51:27Z")

</div>

If I set the size to 32 (which is the size of the elements in the compound type) it works. However I get an exception when trying to write to a file.

---

<div class="post-metadata">

**Author:** ![contact](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/contact/32/1067_2.png) [@contact](https://forum.hdfgroup.org/u/contact)\
**Post date:** [November 21, 2024, 5:12pm UTC](https://forum.hdfgroup.org/t/help-with-array-of-compound-type/12811/4 "2024-11-21T17:12:44Z")

</div>

Hi @vince.gibson,

Given that the issue described in your post is not very clear, would you mind sharing the C# code and the HDF5 file it generates, as well as indicating the HDF5 object stored in this file that you want to retrieve the dimensions from? This will help the community to better understand the issue and eventually help you with it.

---

<div class="post-metadata">

**Author:** ![vince.gibson](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/v/e68b1a/32.png) [@vince.gibson](https://forum.hdfgroup.org/u/vince.gibson)\
**Post date:** [November 21, 2024, 8:21pm UTC](https://forum.hdfgroup.org/t/help-with-array-of-compound-type/12811/5 "2024-11-21T20:21:48Z")

</div>

This is the code to create the dataset:

// Create compound type for headers  
// Variable length string for model name type  
hid\_t header\_model\_name\_t = H5T.create(H5T.class\_t.STRING, H5T.VARIABLE);  
Debug.Assert(STRING\_TYPE\_SIZE == (int)H5T.get\_size(header\_model\_name\_t));

// Variable length string for message name type  
hid\_t header\_message\_name\_t = H5T.create(H5T.class\_t.STRING, H5T.VARIABLE);  
Debug.Assert(STRING\_TYPE\_SIZE == (int)H5T.get\_size(header\_message\_name\_t));

// a variable-length array type  
hid\_t eight\_bit\_t = H5T.copy(H5T.NATIVE\_UINT8);  
hid\_t header\_vlba = H5T.vlen\_create(eight\_bit\_t);  
int data\_payload\_size = (int)H5T.get\_size(header\_vlba);

// Size for Model name (string), Message name (string) and variable length data  
int temp\_header\_size = STRING\_TYPE\_SIZE + STRING\_TYPE\_SIZE + data\_payload\_size;  
\_header\_kvt = H5T.create(H5T.class\_t.COMPOUND, temp\_header\_size);  
int header\_offset = 0;  
Check\_HDF(H5T.insert(\_header\_kvt, “header\_model\_name”, header\_offset, header\_model\_name\_t));  
header\_offset += STRING\_TYPE\_SIZE;  
Check\_HDF(H5T.insert(\_header\_kvt, “header\_message\_name”, header\_offset, header\_message\_name\_t));  
header\_offset += STRING\_TYPE\_SIZE;  
Check\_HDF(H5T.insert(\_header\_kvt, “header\_message\_data”, header\_offset, header\_vlba));

// Fixed length timestamp type  
hid\_t timestamp\_t = H5T.copy(H5T.IEEE\_F64LE);  
Debug.Assert(TIMESTAMP\_SIZE == (int)H5T.get\_size(timestamp\_t));

// Connection type  
hid\_t connection\_t = H5T.copy(H5T.NATIVE\_INT32);  
Debug.Assert(CONNECTION\_SIZE == (int)H5T.get\_size(connection\_t));

// Variable length string for message name type  
hid\_t message\_name\_t = H5T.create(H5T.class\_t.STRING, H5T.VARIABLE);  
Debug.Assert(MESSAGE\_NAME\_SIZE == (int)H5T.get\_size(message\_name\_t));

// Variable length string for the publisher type  
hid\_t publisher\_t = H5T.create(H5T.class\_t.STRING, H5T.VARIABLE);  
Debug.Assert(MESSAGE\_NAME\_SIZE == (int)H5T.get\_size(publisher\_t));

// a variable-length array type  
hid\_t vlba = H5T.vlen\_create(eight\_bit\_t);

int vl\_data\_size = (int)H5T.get\_size(vlba);

// One dimensional array of compound types  
hsize\_t[] max\_dims = { H5S.UNLIMITED };  
hid\_t header\_array = H5T.array\_create(\_header\_kvt, 1, max\_dims);  
Check\_HDF(header\_array);  
Check\_HDF(H5T.set\_size(header\_array, 32));  
int header\_data\_size = 32; // (int)H5T.get\_size(header\_array);  
//Check\_HDF(header\_data\_size);

// Create compound type  
int temp\_size = TIMESTAMP\_SIZE + CONNECTION\_SIZE + MESSAGE\_NAME\_SIZE + PUBLISHER\_SIZE + vl\_data\_size + (int)header\_data\_size;  
\_kvt = H5T.create(H5T.class\_t.COMPOUND, temp\_size);  
int offset = 0;  
Check\_HDF(H5T.insert(\_kvt, “time stamp us”, offset, timestamp\_t));  
offset += TIMESTAMP\_SIZE;  
Check\_HDF(H5T.insert(\_kvt, “connection”, offset, connection\_t));  
offset += CONNECTION\_SIZE;  
Check\_HDF(H5T.insert(\_kvt, “message\_name”, offset, message\_name\_t));  
offset += MESSAGE\_NAME\_SIZE;  
Check\_HDF(H5T.insert(\_kvt, “publisher”, offset, publisher\_t));  
offset += PUBLISHER\_SIZE;  
Check\_HDF(H5T.insert(\_kvt, “data”, offset, vlba));  
offset += (int)vl\_data\_size;  
Check\_HDF(H5T.insert(\_kvt, “headers”, offset, header\_array));

---

<div class="post-metadata">

**Author:** ![bmribler](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@bmribler](https://forum.hdfgroup.org/u/bmribler)\
**Post date:** [November 21, 2024, 8:24pm UTC](https://forum.hdfgroup.org/t/help-with-array-of-compound-type/12811/6 "2024-11-21T20:24:28Z")

</div>

Hi @vince.gibson,

Please check out this post: [Trouble using HDF.PInvoke in c# - #3 by gheber](https://forum.hdfgroup.org/t/trouble-using-hdf-pinvoke-in-c/11898/3) for an alternative.
