closeAllHDF5Handles
C++ Function Reference
1 Signature
void BigDataStatMeth::closeAllHDF5Handles()2 Description
Close all open HDF5 handles at the C library level.
3 Details
Uses HDF5 C API to find and close all open objects (files, datasets, groups, datatypes, attributes) regardless of how they were opened. Equivalent to rhdf5::h5closeAll(). Safe to call at any time — invalid IDs are skipped silently.
4 Source Code
NoteImplementation
File: inst/include/hdf5Utilities/hdf5CheckClose.hpp • Lines 108-123
inline void closeAllHDF5Handles() {
try {
// Exclude H5F_OBJ_DATATYPE: the HDF5 library keeps pre-defined types
// (H5T_NATIVE_DOUBLE, etc.) permanently open as library-level objects.
// Closing them corrupts the library state for subsequent operations.
const unsigned types = H5F_OBJ_FILE | H5F_OBJ_DATASET |
H5F_OBJ_GROUP | H5F_OBJ_ATTR;
ssize_t n = H5Fget_obj_count(H5F_OBJ_ALL, types);
if (n <= 0) return;
std::vector<hid_t> ids(static_cast<size_t>(n));
H5Fget_obj_ids(H5F_OBJ_ALL, types,
static_cast<size_t>(n), ids.data());
for (hid_t id : ids)
if (H5Iis_valid(id) > 0) H5Oclose(id);
} catch (...) {}
}5 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = closeAllHDF5Handles(...);