Thanks for the feedback!
Try the following:
[StructLayout(LayoutKind.Sequential, Pack = 0)]
unsafe struct Data
{
public fixed byte Name[3];
public int Age;
public double Weight;
}
public unsafe static void Main(string []args)
{
Data []values = new Data[100];
for(int i = 0; i < 100; i++)
{
fixed (Data* p = &(values[i]))
{
p->Name[0] = (byte) 'J';
p->Name[1] = (byte) 'o';
p->Name[2] = (byte) 'e';
}
values[i].Age = i;
values[i].Weight = i;
}
HDFql.Execute("CREATE FILE painters.h5");
HDFql.Execute("USE FILE painters.h5");
HDFql.Execute("CREATE GROUP picasso ORDER TRACKED");
HDFql.Execute("CREATE DATASET picasso/guernica AS COMPOUND(name AS CHAR(3), age AS UNSIGNED INT, weight AS DOUBLE)(100) VALUES FROM MEMORY " + HDFql.VariableTransientRegister(values) + " OFFSET(0, 4, 8)");
}
Please notice that members’ offsets (i.e. 0, 4 and 8) are hard-coded in the above code snippet. To have the code more portable/robust, you should use an appropriate C# method that calculates and returns the members’ offsets (within struct Data
) instead. Also, you need to compile the code with the /unsafe
parameter.
FYI, we have improved the way the HDFql C# wrapper handles variables that cannot be pinned (by C# GC) when registering these (which was the case you were facing). Now, instead of finishing abruptly due to an exception, the wrapper handles graciously this case by returning an error (HDFql.ErrorUnexpectedDataType
). This improvement should be available in the next official release of HDFql.