Вопрос

If an HDF5 file is not closed with H5close() or something it is not readable by hdfview. In regular applications the HDF5 file closes correctly but, sometimes, something happens with the code (e.g. segfault) and the file is not closed. In these circumstances, looking at what might be inside the HDF5 file might provide insight into the reason of the error.

Is there a way to achieve this?

Это было полезно?

Решение

You can in general make your reference to the HDF5 file exception safe by following the standard RAII (Resource Acquisition is Initialization) paradigm. This will not, however, protect you from segfaults which are an operating system generated interrupt to your program, unless you catch the interrupt and close the file.

For the simpler case of exception safety, this can be achieved through a couple of best practices. First, acquire the resource during the call to the object constructor. Write a copy constructor and overload the assignment operator to correctly transfer ownership of the file handle rather than simply holding the pointer from two places. Finally, write a destructor for the object that correctly closes the file handle.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top