|
H5CPP
v1.14.0
Modern C++ templates for HDF5 serial and parallel I/O
|
|
Most h5cpp examples write containers (arma::mat, std::vector<T>, Eigen::Matrix, ...) so the library can deduce shape, element type, and storage layout from per-container access traits. When you only have a bare pointer and a length — embedded code, FFI boundary, scratch buffer — you opt out of that machinery and describe the move yourself:
The h5::count{...} is the dataspace shape; the optional h5::offset{...} is the file-space anchor. There is no separate "memory offset" — to write into the middle of a buffer, pass ptr + k.
| File | What it teaches |
|---|---|
raw.cpp | The full positional argument vocabulary for h5::create, plus raw-pointer write / read with offset. |
Expected output:
h5::create<T> has up to seven positional arguments:
Any argument can be omitted; the order is enforced. The example shows four equivalent ways to create the same dataset by combining or hoisting these blocks:
| Form | What's spelled out |
|---|---|
| inline pipe-chained dcpl | h5::chunk{...} \| h5::gzip{...} \| ... |
named h5::dcpl_t variable | reuse across multiple h5::create calls |
| all defaults explicit | h5::default_lcpl, dcpl, h5::default_dapl |
| max_dims only | current_dims = max_dims with H5S_UNLIMITED → 0 |
The max_dims-only form is what packet tables build on top of: a dataset starts empty and grows along its unlimited dimension as h5::append lands chunks.
The library doesn't auto-resize; the buffer's count[0] * count[1] * ... * count[rank-1] elements must be addressable from the pointer you pass.
There is no h5::dst_offset{...} argument. The destination offset is the pointer:
The same trick works for h5::write if you want to write a slice of a larger memory buffer.
Pick raw-pointer I/O when:
extern "C", CUDA host buffer, MPI scratch space).mmap view) and don't want h5cpp to re-allocate.For everything else, use the container path — h5cpp picks the right shape automatically and the call shape stays cleaner.
| Target | Status |
|---|---|
examples-raw | ✔ ok — write/read round-trips verified for double* and int32* paths. |
No external library dependencies.
examples/datasets/** — the full offset/count/stride/block hyperslab vocabulary used here, with prose.examples/optimized/** — the inner-loop pattern of repeated raw-pointer writes into a chunked dataset.examples/packet-table/packet_batches.cpp** — raw-pointer h5::append(pt, ptr) used to stream chunks at maximum throughput.h5cpp/H5Dwrite.hpp / H5Dread.hpp** — the pointer overloads invoked by h5::write<T>(fd, path, T*, ...) / h5::read<T>(fd, path, T*, ...).raw.cpp — rendered with syntax highlighting