H5public.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * Copyright by The HDF Group. *
  3. * Copyright by the Board of Trustees of the University of Illinois. *
  4. * All rights reserved. *
  5. * *
  6. * This file is part of HDF5. The full HDF5 copyright notice, including *
  7. * terms governing use, modification, and redistribution, is contained in *
  8. * the COPYING file, which can be found at the root of the source code *
  9. * distribution tree, or in https://www.hdfgroup.org/licenses. *
  10. * If you do not have access to either file, you may request a copy from *
  11. * help@hdfgroup.org. *
  12. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  13. /*
  14. * This file contains public declarations for the HDF5 module.
  15. */
  16. #ifndef H5public_H
  17. #define H5public_H
  18. /* Include files for public use... */
  19. /*
  20. * Since H5pubconf.h is a generated header file, it is messy to try
  21. * to put a #ifndef H5pubconf_H ... #endif guard in it.
  22. * HDF5 has set an internal rule that it is being included here.
  23. * Source files should NOT include H5pubconf.h directly but include
  24. * it via H5public.h. The #ifndef H5public_H guard above would
  25. * prevent repeated include.
  26. */
  27. #include "H5pubconf.h" /* From configure */
  28. /* API Version macro wrapper definitions */
  29. #include "H5version.h"
  30. #ifdef H5_HAVE_FEATURES_H
  31. #include <features.h> /* For setting POSIX, BSD, etc. compatibility */
  32. #endif
  33. /* C library header files for things that appear in HDF5 public headers */
  34. #ifdef __cplusplus
  35. #define __STDC_FORMAT_MACROS
  36. #endif
  37. #include <inttypes.h>
  38. #include <limits.h>
  39. #include <stdarg.h>
  40. #include <stdbool.h>
  41. #include <stddef.h>
  42. #include <stdint.h>
  43. /* Unlike most sys/ headers, which are POSIX-only, sys/types.h is available
  44. * on Windows, though it doesn't necessarily contain all the POSIX types
  45. * we need for HDF5 (e.g. ssize_t).
  46. */
  47. #ifdef H5_HAVE_SYS_TYPES_H
  48. #include <sys/types.h>
  49. #endif
  50. #ifdef H5_HAVE_PARALLEL
  51. /* Don't link against MPI C++ bindings */
  52. #ifndef MPICH_SKIP_MPICXX
  53. #define MPICH_SKIP_MPICXX 1
  54. #endif
  55. #ifndef OMPI_SKIP_MPICXX
  56. #define OMPI_SKIP_MPICXX 1
  57. #endif
  58. #include <mpi.h>
  59. #ifndef MPI_FILE_NULL /* MPIO may be defined in mpi.h already */
  60. #include <mpio.h>
  61. #endif
  62. #endif
  63. /* Macro to hide a symbol from further preprocessor substitutions */
  64. #define H5_NO_EXPAND(x) (x)
  65. /* Version numbers */
  66. /**
  67. * For major interface/format changes
  68. */
  69. #define H5_VERS_MAJOR 1
  70. /**
  71. * For minor interface/format changes
  72. */
  73. #define H5_VERS_MINOR 13
  74. /**
  75. * For tweaks, bug-fixes, or development
  76. */
  77. #define H5_VERS_RELEASE 1
  78. /**
  79. * For pre-releases like \c snap0. Empty string for official releases.
  80. */
  81. #define H5_VERS_SUBRELEASE ""
  82. /**
  83. * Full version string
  84. */
  85. #define H5_VERS_INFO "HDF5 library version: 1.13.1"
  86. #define H5check() H5check_version(H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE)
  87. /* macros for comparing the version */
  88. /**
  89. * \brief Determines whether the version of the library being used is greater
  90. * than or equal to the specified version
  91. *
  92. * \param[in] Maj Major version number - A non-negative integer value
  93. * \param[in] Min Minor version number - A non-negative integer value
  94. * \param[in] Rel Release version number - A non-negative integer value
  95. * \returns A value of 1 is returned if the library version is greater than
  96. * or equal to the version number specified.\n
  97. * A value of 0 is returned if the library version is less than the
  98. * version number specified.\n
  99. * A library version is greater than the specified version number if
  100. * its major version is larger than the specified major version
  101. * number. If the major version numbers are the same, it is greater
  102. * than the specified version number if its minor version is larger
  103. * than the specified minor version number. If the minor version
  104. * numbers are the same, then a library version would be greater than
  105. * the specified version number if its release number is larger than
  106. * the specified release number.
  107. *
  108. * \details The #H5_VERSION_GE and #H5_VERSION_LE macros are used at compile
  109. * time to conditionally include or exclude code based on the version
  110. * of the HDF5 library against which an application will be linked.
  111. *
  112. * The #H5_VERSION_GE macro compares the version of the HDF5 library
  113. * being used against the version number specified in the parameters.
  114. *
  115. * For more information about release versioning, see \ref_h5lib_relver.
  116. *
  117. * \since 1.8.7
  118. *
  119. */
  120. #define H5_VERSION_GE(Maj, Min, Rel) \
  121. (((H5_VERS_MAJOR == Maj) && (H5_VERS_MINOR == Min) && (H5_VERS_RELEASE >= Rel)) || \
  122. ((H5_VERS_MAJOR == Maj) && (H5_VERS_MINOR > Min)) || (H5_VERS_MAJOR > Maj))
  123. /**
  124. * \brief Determines whether the version of the library being used is less
  125. * than or equal to the specified version
  126. *
  127. * \param[in] Maj Major version number - A non-negative integer value
  128. * \param[in] Min Minor version number - A non-negative integer value
  129. * \param[in] Rel Release version number - A non-negative integer value
  130. * \returns A value of 1 is returned if the library version is less than
  131. * or equal to the version number specified.\n
  132. * A value of 0 is returned if the library version is greater than the
  133. * version number specified.\n
  134. * A library version is less than the specified version number if
  135. * its major version is smaller than the specified major version
  136. * number. If the major version numbers are the same, it is smaller
  137. * than the specified version number if its minor version is smaller
  138. * than the specified minor version number. If the minor version
  139. * numbers are the same, then a library version would be smaller than
  140. * the specified version number if its release number is smaller than
  141. * the specified release number.
  142. *
  143. * \details The #H5_VERSION_GE and #H5_VERSION_LE macros are used at compile
  144. * time to conditionally include or exclude code based on the version
  145. * of the HDF5 library against which an application will be linked.
  146. *
  147. * The #H5_VERSION_LE macro compares the version of the HDF5 library
  148. * being used against the version number specified in the parameters.
  149. *
  150. * For more information about release versioning, see \ref_h5lib_relver.
  151. *
  152. * \since 1.8.7
  153. *
  154. */
  155. #define H5_VERSION_LE(Maj, Min, Rel) \
  156. (((H5_VERS_MAJOR == Maj) && (H5_VERS_MINOR == Min) && (H5_VERS_RELEASE <= Rel)) || \
  157. ((H5_VERS_MAJOR == Maj) && (H5_VERS_MINOR < Min)) || (H5_VERS_MAJOR < Maj))
  158. /* Macros for various environment variables that HDF5 interprets */
  159. /**
  160. * Used to specify the name of an HDF5 Virtual File Driver to use as
  161. * the default file driver for file access. Setting this environment
  162. * variable overrides the default file driver for File Access Property
  163. * Lists.
  164. */
  165. #define HDF5_DRIVER "HDF5_DRIVER"
  166. /**
  167. * Used to specify a configuration string for the HDF5 Virtual File
  168. * Driver being used for file access.
  169. */
  170. #define HDF5_DRIVER_CONFIG "HDF5_DRIVER_CONFIG"
  171. /**
  172. * Used to specify the name of an HDF5 Virtual Object Layer Connector
  173. * to use as the default VOL connector for file access. Setting this
  174. * environment variable overrides the default VOL connector for File
  175. * Access Property Lists.
  176. */
  177. #define HDF5_VOL_CONNECTOR "HDF5_VOL_CONNECTOR"
  178. /**
  179. * Used to specify a delimiter-separated (currently, ';' for Windows
  180. * and ':' for other systems) list of paths that HDF5 should search
  181. * when loading plugins.
  182. */
  183. #define HDF5_PLUGIN_PATH "HDF5_PLUGIN_PATH"
  184. /**
  185. * Used to control the loading of HDF5 plugins at runtime. If this
  186. * environment variable is set to the special string "::" (defined
  187. * in H5PLpublic.h as H5PL_NO_PLUGIN), then dynamic loading of any
  188. * HDF5 plugins will be disabled. No other values are valid for this
  189. * environment variable.
  190. */
  191. #define HDF5_PLUGIN_PRELOAD "HDF5_PLUGIN_PRELOAD"
  192. /**
  193. * Used to control whether HDF5 uses file locking when creating or
  194. * opening a file. Valid values for this environment variable are
  195. * as follows:
  196. *
  197. * "TRUE" or "1" - Request that file locks should be used
  198. * "FALSE" or "0" - Request that file locks should NOT be used
  199. * "BEST_EFFORT" - Request that file locks should be used and
  200. * that any locking errors caused by file
  201. * locking being disabled on the system
  202. * should be ignored
  203. */
  204. #define HDF5_USE_FILE_LOCKING "HDF5_USE_FILE_LOCKING"
  205. /**
  206. * Used to instruct HDF5 not to cleanup files created during testing.
  207. */
  208. #define HDF5_NOCLEANUP "HDF5_NOCLEANUP"
  209. /**
  210. * Status return values. Failed integer functions in HDF5 result almost
  211. * always in a negative value (unsigned failing functions sometimes return
  212. * zero for failure) while successful return is non-negative (often zero).
  213. * The negative failure value is most commonly -1, but don't bet on it.
  214. *
  215. * The proper way to detect failure is something like:
  216. * \code
  217. * if((dset = H5Dopen2(file, name)) < 0)
  218. * fprintf(stderr, "unable to open the requested dataset\n");
  219. * \endcode
  220. */
  221. typedef int herr_t;
  222. /**
  223. * C99-style Boolean type. Successful return values are zero (false) or positive
  224. * (true). The typical true value is 1 but don't bet on it.
  225. * \attention Boolean functions cannot fail.
  226. */
  227. #include <stdbool.h>
  228. typedef bool hbool_t;
  229. /**
  230. * Three-valued Boolean type. Functions that return #htri_t however return zero
  231. * (false), positive (true), or negative (failure).
  232. *
  233. * The proper way to test for truth from a #htri_t function is:
  234. * \code
  235. * if ((retval = H5Tcommitted(type)) > 0) {
  236. * printf("data type is committed\n");
  237. * } else if (!retval) {
  238. * printf("data type is not committed\n");
  239. * } else {
  240. * printf("error determining whether data type is committed\n");
  241. * }
  242. * \endcode
  243. */
  244. typedef int htri_t;
  245. /* The signed version of size_t
  246. *
  247. * ssize_t is POSIX and not defined in any C standard. It's used in some
  248. * public HDF5 API calls so this work-around will define it if it's not
  249. * present.
  250. *
  251. * Use of ssize_t should be discouraged in new code.
  252. */
  253. #if H5_SIZEOF_SSIZE_T == 0
  254. /* Undefine this size, we will re-define it in one of the sections below */
  255. #undef H5_SIZEOF_SSIZE_T
  256. #if H5_SIZEOF_SIZE_T == H5_SIZEOF_INT
  257. typedef int ssize_t;
  258. #define H5_SIZEOF_SSIZE_T H5_SIZEOF_INT
  259. #elif H5_SIZEOF_SIZE_T == H5_SIZEOF_LONG
  260. typedef long ssize_t;
  261. #define H5_SIZEOF_SSIZE_T H5_SIZEOF_LONG
  262. #elif H5_SIZEOF_SIZE_T == H5_SIZEOF_LONG_LONG
  263. typedef long long ssize_t;
  264. #define H5_SIZEOF_SSIZE_T H5_SIZEOF_LONG_LONG
  265. #else /* Can't find matching type for ssize_t */
  266. #error "nothing appropriate for ssize_t"
  267. #endif
  268. #endif
  269. /**
  270. * The size of file objects.
  271. *
  272. * \internal Defined as a (minimum) 64-bit integer type.
  273. */
  274. typedef uint64_t hsize_t;
  275. #ifdef H5_HAVE_PARALLEL
  276. #define HSIZE_AS_MPI_TYPE MPI_UINT64_T
  277. #endif
  278. /**
  279. * The size of file objects. Used when negative values are needed to indicate errors.
  280. *
  281. * \internal Defined as a (minimum) 64-bit integer type. Use of hssize_t
  282. * should be discouraged in new code.
  283. */
  284. typedef int64_t hssize_t;
  285. #define PRIdHSIZE PRId64
  286. #define PRIiHSIZE PRIi64
  287. #define PRIoHSIZE PRIo64
  288. #define PRIuHSIZE PRIu64
  289. #define PRIxHSIZE PRIx64
  290. #define PRIXHSIZE PRIX64
  291. #define H5_SIZEOF_HSIZE_T 8
  292. #define H5_SIZEOF_HSSIZE_T 8
  293. #define HSIZE_UNDEF UINT64_MAX
  294. /**
  295. * The address of an object in the file.
  296. *
  297. * \internal Defined as a (minimum) 64-bit unsigned integer type.
  298. */
  299. typedef uint64_t haddr_t;
  300. #define PRIdHADDR PRId64
  301. #define PRIoHADDR PRIo64
  302. #define PRIuHADDR PRIu64
  303. #define PRIxHADDR PRIx64
  304. #define PRIXHADDR PRIX64
  305. #define H5_SIZEOF_HADDR_T 8
  306. #define HADDR_UNDEF UINT64_MAX
  307. #define H5_PRINTF_HADDR_FMT "%" PRIuHADDR
  308. #define HADDR_MAX (HADDR_UNDEF - 1)
  309. #ifdef H5_HAVE_PARALLEL
  310. #define HADDR_AS_MPI_TYPE MPI_UINT64_T
  311. #endif
  312. //! <!-- [H5_iter_order_t_snip] -->
  313. /**
  314. * Common iteration orders
  315. */
  316. typedef enum {
  317. H5_ITER_UNKNOWN = -1, /**< Unknown order */
  318. H5_ITER_INC, /**< Increasing order */
  319. H5_ITER_DEC, /**< Decreasing order */
  320. H5_ITER_NATIVE, /**< No particular order, whatever is fastest */
  321. H5_ITER_N /**< Number of iteration orders */
  322. } H5_iter_order_t;
  323. //! <!-- [H5_iter_order_t_snip] -->
  324. /* Iteration callback values */
  325. /* (Actually, any positive value will cause the iterator to stop and pass back
  326. * that positive value to the function that called the iterator)
  327. */
  328. #define H5_ITER_ERROR (-1) /**< Error, stop iteration */
  329. #define H5_ITER_CONT (0) /**< Continue iteration */
  330. #define H5_ITER_STOP (1) /**< Stop iteration, short-circuit success */
  331. //! <!-- [H5_index_t_snip] -->
  332. /**
  333. * The types of indices on links in groups/attributes on objects.
  334. * Primarily used for "<do> <foo> by index" routines and for iterating over
  335. * links in groups/attributes on objects.
  336. */
  337. typedef enum H5_index_t {
  338. H5_INDEX_UNKNOWN = -1, /**< Unknown index type */
  339. H5_INDEX_NAME, /**< Index on names */
  340. H5_INDEX_CRT_ORDER, /**< Index on creation order */
  341. H5_INDEX_N /**< Number of indices defined */
  342. } H5_index_t;
  343. //! <!-- [H5_index_t_snip] -->
  344. /**
  345. * Storage info struct used by H5O_info_t and H5F_info_t
  346. */
  347. //! <!-- [H5_ih_info_t_snip] -->
  348. typedef struct H5_ih_info_t {
  349. hsize_t index_size; /**< btree and/or list */
  350. hsize_t heap_size;
  351. } H5_ih_info_t;
  352. //! <!-- [H5_ih_info_t_snip] -->
  353. /**
  354. * The maximum size allowed for tokens
  355. * \details Tokens are unique and permanent identifiers that are
  356. * used to reference HDF5 objects in a container. This allows
  357. * for 128-bit tokens
  358. */
  359. #define H5O_MAX_TOKEN_SIZE (16)
  360. //! <!-- [H5O_token_t_snip] -->
  361. /**
  362. * Type for object tokens
  363. *
  364. * \internal (Hoisted here, since it's used by both the
  365. * H5Lpublic.h and H5Opublic.h headers)
  366. */
  367. typedef struct H5O_token_t {
  368. uint8_t __data[H5O_MAX_TOKEN_SIZE];
  369. } H5O_token_t;
  370. //! <!-- [H5O_token_t_snip] -->
  371. /**
  372. * Allocation statistics info struct
  373. */
  374. typedef struct H5_alloc_stats_t {
  375. unsigned long long total_alloc_bytes; /**< Running count of total # of bytes allocated */
  376. size_t curr_alloc_bytes; /**< Current # of bytes allocated */
  377. size_t peak_alloc_bytes; /**< Peak # of bytes allocated */
  378. size_t max_block_size; /**< Largest block allocated */
  379. size_t total_alloc_blocks_count; /**< Running count of total # of blocks allocated */
  380. size_t curr_alloc_blocks_count; /**< Current # of blocks allocated */
  381. size_t peak_alloc_blocks_count; /**< Peak # of blocks allocated */
  382. } H5_alloc_stats_t;
  383. /**
  384. * Library shutdown callback, used by H5atclose().
  385. */
  386. typedef void (*H5_atclose_func_t)(void *ctx);
  387. /* API adapter header (defines H5_DLL, etc.) */
  388. #include "H5api_adpt.h"
  389. #ifdef __cplusplus
  390. extern "C" {
  391. #endif
  392. /* Functions in H5.c */
  393. /**
  394. * \ingroup H5
  395. * \brief Initializes the HDF5 library
  396. * \return \herr_t
  397. *
  398. * \details H5open() initializes the HDF5 library.
  399. *
  400. * \details When the HDF5 library is used in a C application, the library is
  401. * automatically initialized when the first HDf5 function call is
  402. * issued. If one finds that an HDF5 library function is failing
  403. * inexplicably, H5open() can be called first. It is safe to call
  404. * H5open() before an application issues any other function calls to
  405. * the HDF5 library as there are no damaging side effects in calling
  406. * it more than once.
  407. */
  408. H5_DLL herr_t H5open(void);
  409. /**
  410. * \ingroup H5
  411. * \brief Registers a callback for the library to invoke when it's closing.
  412. * \param[in] func The function pointer to invoke
  413. * \param[in] ctx Context to pass to \p func when invoked
  414. * \return \herr_t
  415. *
  416. * \details H5atclose() registers a callback that the HDF5 library will invoke
  417. * when closing. The full capabilities of the HDF5 library are
  418. * available to callbacks invoked through this mechanism, library
  419. * shutdown will only begin in earnest when all callbacks have been
  420. * invoked and have returned.
  421. *
  422. * Registered callbacks are invoked in LIFO order, similar to the
  423. * Standard C 'atexit' routine. For example, if 'func1' is registered,
  424. * then 'func2', when the library is closing 'func2' will
  425. * be invoked first, then 'func1'.
  426. *
  427. * The \p ctx pointer will be passed to \p func when it's invoked.
  428. * NULL is allowed for \p ctx.
  429. *
  430. * If the HDF5 library is initialized and closed more than once, the
  431. * \p func callback must be registered within each open/close cycle.
  432. *
  433. * \since 1.13.0
  434. */
  435. H5_DLL herr_t H5atclose(H5_atclose_func_t func, void *ctx);
  436. /**
  437. * \ingroup H5
  438. * \brief Flushes all data to disk, closes all open objects, and releases memory
  439. * \return \herr_t
  440. *
  441. * \details H5close() flushes all data to disk, closes all open HDF5 objects,
  442. * and cleans up all memory used by the HDF5 library. This function is
  443. * generally called when the application calls exit(), but may be
  444. * called earlier in the event of an emergency shutdown or out of a
  445. * desire to free all resources used by the HDF5 library.
  446. */
  447. H5_DLL herr_t H5close(void);
  448. /**
  449. * \ingroup H5
  450. * \brief Instructs library not to install atexit() cleanup routine
  451. * \return \herr_t
  452. *
  453. * \details H5dont_atexit() indicates to the library that an atexit() cleanup
  454. * routine should not be installed. The major purpose for using this
  455. * function is in situations where the library is dynamically linked
  456. * into an application and is un-linked from the application before
  457. * exit() gets called. In those situations, a routine installed with
  458. * atexit() would jump to a routine which was no longer in memory,
  459. * causing errors.
  460. *
  461. * \attention In order to be effective, this routine \Emph{must} be called
  462. * before any other HDF5 function calls, and must be called each
  463. * time the library is loaded/linked into the application (the first
  464. * time and after it's been un-loaded).
  465. */
  466. H5_DLL herr_t H5dont_atexit(void);
  467. /**
  468. * \ingroup H5
  469. * \brief Garbage collects on all free-lists of all types
  470. * \return \herr_t
  471. *
  472. * \details H5garbage_collect() walks through all garbage collection routines
  473. * of the library, freeing any unused memory.
  474. *
  475. * It is not required that H5garbage_collect() be called at any
  476. * particular time; it is only necessary in certain situations where
  477. * the application has performed actions that cause the library to
  478. * allocate many objects. The application should call
  479. * H5garbage_collect() if it eventually releases those objects and
  480. * wants to reduce the memory used by the library from the peak usage
  481. * required.
  482. *
  483. * \note The library automatically garbage collects all the free lists when the
  484. * application ends.
  485. */
  486. H5_DLL herr_t H5garbage_collect(void);
  487. /**
  488. * \ingroup H5
  489. * \brief Sets free-list size limits
  490. *
  491. * \param[in] reg_global_lim The cumulative limit, in bytes, on memory used for
  492. * all regular free lists (Default: 1MB)
  493. * \param[in] reg_list_lim The limit, in bytes, on memory used for each regular
  494. * free list (Default: 64KB)
  495. * \param[in] arr_global_lim The cumulative limit, in bytes, on memory used for
  496. * all array free lists (Default: 4MB)
  497. * \param[in] arr_list_lim The limit, in bytes, on memory used for each array
  498. * free list (Default: 256KB)
  499. * \param[in] blk_global_lim The cumulative limit, in bytes, on memory used for
  500. * all block free lists and, separately, for all
  501. * factory free lists (Default: 16MB)
  502. * \param[in] blk_list_lim The limit, in bytes, on memory used for each block
  503. * or factory free list (Default: 1MB)
  504. * \return \herr_t
  505. *
  506. * \details H5set_free_list_limits() sets size limits on all types of free
  507. * lists. The HDF5 library uses free lists internally to manage
  508. * memory. The types of free lists used are as follows:
  509. * \li Regular free lists manage memory for single internal data
  510. * structures.
  511. * \li Array free lists manage memory for arrays of internal
  512. * data structures.
  513. * \li Block free lists manage memory for arbitrarily-sized blocks
  514. * of bytes.
  515. * \li Factory free lists manage memory for fixed-size blocks of
  516. * bytes.
  517. *
  518. * The parameters specify global and per-list limits; for example, \p
  519. * reg_global_limit and \p reg_list_limit limit the accumulated size
  520. * of all regular free lists and the size of each individual regular
  521. * free list, respectively. Therefore, if an application sets a 1Mb
  522. * limit on each of the global lists, up to 4Mb of total storage might
  523. * be allocated, 1Mb for each of the regular, array, block, and
  524. * factory type lists.
  525. *
  526. * The settings specified for block free lists are duplicated for
  527. * factory free lists. Therefore, increasing the global limit on block
  528. * free lists by x bytes will increase the potential free list memory
  529. * usage by 2x bytes.
  530. *
  531. * Using a value of -1 for a limit means that no limit is set for the
  532. * specified type of free list.
  533. *
  534. * \version 1.8.3 Function changed in this release to set factory free list
  535. * memory limits.
  536. *
  537. * \since 1.6.0
  538. */
  539. H5_DLL herr_t H5set_free_list_limits(int reg_global_lim, int reg_list_lim, int arr_global_lim,
  540. int arr_list_lim, int blk_global_lim, int blk_list_lim);
  541. /**
  542. * \ingroup H5
  543. * \brief Gets the current size of the free lists used to manage memory
  544. *
  545. * \param[out] reg_size The current size of all "regular" free list memory used
  546. * \param[out] arr_size The current size of all "array" free list memory used
  547. * \param[out] blk_size The current size of all "block" free list memory used
  548. * \param[out] fac_size The current size of all "factory" free list memory used
  549. * \return \herr_t
  550. *
  551. * \details H5get_free_list_sizes() obtains the current size of the different
  552. * kinds of free lists that the library uses to manage memory. The
  553. * free list sizes can be set with H5set_free_list_limits() and
  554. * garbage collected with H5garbage_collect(). These lists are global
  555. * for the entire library.
  556. *
  557. * \since 1.12.1
  558. */
  559. H5_DLL herr_t H5get_free_list_sizes(size_t *reg_size, size_t *arr_size, size_t *blk_size, size_t *fac_size);
  560. /**
  561. * \ingroup H5
  562. * \brief Gets the memory allocation statistics for the library
  563. *
  564. * \param[out] stats Memory allocation statistics
  565. * \return \herr_t
  566. *
  567. * \details H5get_alloc_stats() gets the memory allocation statistics for the
  568. * library, if the \c --enable-memory-alloc-sanity-check option was
  569. * given when building the library. Applications can check whether
  570. * this option was enabled detecting if the
  571. * \c H5_MEMORY_ALLOC_SANITY_CHECK macro is defined. This option is
  572. * enabled by default for debug builds of the library and disabled by
  573. * default for non-debug builds. If the option is not enabled, all the
  574. * values returned with be 0. These statistics are global for the
  575. * entire library, but do not include allocations from chunked dataset
  576. * I/O filters or non-native VOL connectors.
  577. *
  578. * \since 1.12.1
  579. */
  580. H5_DLL herr_t H5get_alloc_stats(H5_alloc_stats_t *stats);
  581. /**
  582. * \ingroup H5
  583. * \brief Returns the HDF library release number
  584. *
  585. * \param[out] majnum The major version number of the library
  586. * \param[out] minnum The minor version number of the library
  587. * \param[out] relnum The release version number of the library
  588. * \return \herr_t
  589. *
  590. * \details H5get_libversion() retrieves the major, minor, and release numbers
  591. * of the version of the HDF5 library which is linked to the
  592. * application.
  593. *
  594. */
  595. H5_DLL herr_t H5get_libversion(unsigned *majnum, unsigned *minnum, unsigned *relnum);
  596. /**
  597. * \ingroup H5
  598. * \brief Verifies that HDF5 library versions are consistent
  599. *
  600. * \param[in] majnum HDF5 library major version number
  601. * \param[in] minnum HDF5 library minor version number
  602. * \param[in] relnum HDF5 library release number
  603. * \return \herr_t
  604. *
  605. * \details H5check_version() verifies that the version of the HDF5 library
  606. * with which an application was compiled, as indicated by the passed
  607. * parameters, matches the version of the HDF5 library against which
  608. * the application is currently linked.
  609. *
  610. * \p majnum is the major version number of the HDF library with which
  611. * the application was compiled, \p minnum is the minor version
  612. * number, and \p relnum is the release number. Consider the following
  613. * example:
  614. *
  615. * An official HDF5 release is labelled as follows:
  616. * HDF5 Release \Code{\<majnum\>.\<minnum\>.\<relnum\>}\n
  617. * For example, in HDF5 Release 1.8.5:
  618. * \li 1 is the major version number, \p majnum.
  619. * \li 8 is the minor version number, \p minnum.
  620. * \li 5 is the release number, \p relnum.
  621. *
  622. * As stated above, H5check_version() first verifies that the version
  623. * of the HDF5 library with which an application was compiled matches
  624. * the version of the HDF5 library against which the application is
  625. * currently linked. If this check fails, H5check_version() causes the
  626. * application to abort (by means of a standard C abort() call) and
  627. * prints information that is usually useful for debugging. This
  628. * precaution is is taken to avoid the risks of data corruption or
  629. * segmentation faults.
  630. *
  631. * The most common cause of this failure is that an application was
  632. * compiled with one version of HDF5 and is dynamically linked with a
  633. * different version different version.
  634. *
  635. * If the above test passes, H5check_version() proceeds to verify the
  636. * consistency of additional library version information. This is
  637. * designed to catch source code inconsistencies that do not normally
  638. * cause failures; if this check reveals an inconsistency, an
  639. * informational warning is printed but the application is allowed to
  640. * run.
  641. *
  642. */
  643. H5_DLL herr_t H5check_version(unsigned majnum, unsigned minnum, unsigned relnum);
  644. /**
  645. * \ingroup H5
  646. * \brief Checks whether the HDF5 library is closing.
  647. * \param[out] is_terminating Flag indicating whether library is shutting down
  648. * \return \herr_t
  649. *
  650. * \details H5is_library_terminating() queries whether the HDF5 library is in
  651. * the process of shutting down. The \p is_terminating flag will only
  652. * be set to TRUE after shutdown starts, it will be FALSE before the
  653. * library has been initialized, while the library is initialized, and
  654. * after it has been closed. The value of \p is_terminating is
  655. * undefined if this routine fails.
  656. *
  657. * \since 1.13.0
  658. */
  659. H5_DLL herr_t H5is_library_terminating(hbool_t *is_terminating);
  660. /**
  661. * \ingroup H5
  662. * \brief Determines whether the HDF5 library was built with the thread-safety
  663. * feature enabled
  664. *
  665. * \param[out] is_ts Boolean value indicating whether the library was built
  666. * with thread-safety enabled
  667. * \return \herr_t
  668. *
  669. * \details The HDF5 library, although not internally multi-threaded, can be
  670. * built with a thread-safety feature enabled that protects internal
  671. * data structures with a mutex. In certain circumstances, it may be
  672. * useful to determine, at run-time, whether the linked HDF5 library
  673. * was built with the thread-safety feature enabled.
  674. */
  675. H5_DLL herr_t H5is_library_threadsafe(hbool_t *is_ts);
  676. /**
  677. * \ingroup H5
  678. * \brief Frees memory allocated by the HDF5 library
  679. *
  680. * \param[in] mem Buffer to be freed. Can be NULL
  681. * \return \herr_t
  682. *
  683. * \details H5free_memory() frees memory that has been allocated by the caller
  684. * with H5allocate_memory() or by the HDF5 library on behalf of the
  685. * caller.
  686. *
  687. * H5Tget_member_name() provides an example of memory allocation on
  688. * behalf of the caller: The function returns a buffer containing the
  689. * name of a compound datatype member. It is the caller’s
  690. * responsibility to eventually free that buffer with H5free_memory().
  691. *
  692. * \attention It is especially important to use this function to free memory
  693. * allocated by the library on Windows. The C standard library is
  694. * implemented in dynamic link libraries (DLLs) known as the C
  695. * run-time (CRT). Each version of Visual Studio comes with two CRT
  696. * DLLs (debug and release) and allocating and freeing across DLL
  697. * boundaries can cause resource leaks and subtle bugs due to heap
  698. * corruption.\n
  699. * Only use this function to free memory allocated by the HDF5
  700. * Library. It will generally not be safe to use this function to
  701. * free memory allocated by any other means.\n
  702. * Even when using this function, it is still best to ensure that
  703. * all components of a C application are built with the same version
  704. * of Visual Studio and build (debug or release) and thus linked
  705. * against the same CRT.
  706. *
  707. * \see H5allocate_memory(), H5resize_memory()
  708. *
  709. * \since 1.8.13
  710. *
  711. */
  712. H5_DLL herr_t H5free_memory(void *mem);
  713. /**
  714. * \ingroup H5
  715. * \brief Frees memory allocated by the HDF5 library
  716. *
  717. * \param[in] size The size in bytes of the buffer to be allocated
  718. * \param[in] clear Flag whether the new buffer is to be initialized with 0
  719. *
  720. * \return On success, returns pointer to newly allocated buffer or returns
  721. * NULL if size is 0 (zero).\n
  722. * Returns NULL on failure.
  723. *
  724. * \details H5allocate_memory() allocates a memory buffer of size bytes that
  725. * will later be freed internally by the HDF5 library.
  726. *
  727. * The boolean \p clear parameter specifies whether the buffer should
  728. * be initialized. If clear is \c TRUE, all bits in the buffer are to be
  729. * set to 0 (zero); if clear is \c FALSE, the buffer will not be
  730. * initialized.
  731. *
  732. * This function is intended to have the semantics of malloc() and
  733. * calloc(). However, unlike malloc() and calloc() which allow for a
  734. * "special" pointer to be returned instead of NULL, this function
  735. * always returns NULL on failure or when size is set to 0 (zero).
  736. *
  737. * \note At this time, the only intended use for this function is to allocate
  738. * memory that will be returned to the library as a data buffer from a
  739. * third-party filter.
  740. *
  741. * \attention To avoid heap corruption, allocated memory should be freed using
  742. * the same library that initially allocated it. In most cases, the
  743. * HDF5 API uses resources that are allocated and freed either
  744. * entirely by the user or entirely by the library, so this is not a
  745. * problem. In rare cases, however, HDF5 API calls will free memory
  746. * that the user allocated. This function allows the user to safely
  747. * allocate this memory.\n
  748. * It is particularly important to use this function to allocate
  749. * memory in Microsoft Windows environments. In Windows, the C
  750. * standard library is implemented in dynamic link libraries (DLLs)
  751. * known as the C run-time (CRT). Each version of Visual Studio
  752. * comes with multiple versions of the CRT DLLs (debug, release, et
  753. * cetera) and allocating and freeing memory across DLL boundaries
  754. * can cause resource leaks and subtle bugs due to heap corruption.\n
  755. * Even when using this function, it is best where possible to
  756. * ensure that all components of a C application are built with the
  757. * same version of Visual Studio and configuration (Debug or
  758. * Release), and thus linked against the same CRT.\n
  759. * Use this function only to allocate memory inside third-party HDF5
  760. * filters. It will generally not be safe to use this function to
  761. * allocate memory for any other purpose.
  762. *
  763. * \see H5free_memory(), H5resize_memory()
  764. *
  765. * \since 1.8.15
  766. *
  767. */
  768. H5_DLL void *H5allocate_memory(size_t size, hbool_t clear);
  769. /**
  770. * \ingroup H5
  771. * \brief Resizes and, if required, re-allocates memory that will later be
  772. * freed internally by the HDF5 library
  773. *
  774. * \param[in] mem Pointer to a buffer to be resized. May be NULL
  775. * \param[in] size New size of the buffer, in bytes
  776. *
  777. * \return On success, returns pointer to resized or reallocated buffer
  778. * or returns NULL if size is 0 (zero).\n
  779. * Returns NULL on failure.
  780. *
  781. * \details H5resize_memory() takes a pointer to an existing buffer and resizes
  782. * the buffer to match the value in \p size. If necessary, the buffer
  783. * is reallocated. If \p size is 0, the buffer is released.
  784. *
  785. * The input buffer must either be NULL or have been allocated by
  786. * H5allocate_memory() since the input buffer may be freed by the
  787. * library.
  788. *
  789. * For certain behaviors, the pointer \p mem may be passed in as NULL.
  790. *
  791. * This function is intended to have the semantics of realloc():
  792. *
  793. * <table>
  794. * <tr><td>\Code{H5resize_memory(buffer, size)}</td>
  795. * <td>Resizes buffer. Returns pointer to resized buffer.</td></tr>
  796. * <tr><td>\Code{H5resize_memory(NULL, size)}</td>
  797. * <td>Allocates memory using HDF5 Library allocator.
  798. * Returns pointer to new buffer</td></tr>
  799. * <tr><td>\Code{H5resize_memory(buffer, 0)}</td>
  800. * <td>Frees memory using HDF5 Library allocator.
  801. * Returns NULL.</td></tr>
  802. * <tr><td>\Code{H5resize_memory(NULL, 0)}</td>
  803. * <td>Returns NULL (undefined in C standard).</td></tr>
  804. * </table>
  805. *
  806. * Unlike realloc(), which allows for a "special pointer to be
  807. * returned instead of NULL, this function always returns NULL on
  808. * failure or when size is 0 (zero).
  809. *
  810. * \note At this time, the only intended use for this function is to resize or
  811. * reallocate memory that will be returned to the library (and eventually
  812. * to the user) as a data buffer from a third-party HDF5 filter.
  813. *
  814. * \attention To avoid heap corruption, allocated memory should be freed using
  815. * the same library that initially allocated it. In most cases, the
  816. * HDF5 API uses resources that are allocated and freed either
  817. * entirely by the user or entirely by the library, so this is not a
  818. * problem. In rare cases, however, HDF5 API calls will free memory
  819. * that the user allocated. This function allows the user to safely
  820. * allocate this memory.\n
  821. * It is particularly important to use this function to resize
  822. * memory on Microsoft Windows systems. In Windows, the C standard
  823. * library is implemented in dynamic link libraries (DLLs) known as
  824. * the C run-time (CRT). Each version of Visual Studio comes with
  825. * multiple versions of the CRT DLLs (debug, release, et cetera) and
  826. * allocating and freeing memory across DLL boundaries can cause
  827. * resource leaks and subtle bugs due to heap corruption.\n
  828. * Even when using this function, it is still best to ensure that
  829. * all components of a C application are built with the same version
  830. * of Visual Studio and the same configuration (Debug or Release),
  831. * and thus linked against the same CRT.\n
  832. * Only use this function to resize memory inside third-party HDF5
  833. * filters. It will generally not be safe to use this function to
  834. * resize memory for any other purpose.
  835. *
  836. * \see H5allocate_memory(), H5free_memory()
  837. *
  838. * \since 1.8.15
  839. *
  840. */
  841. H5_DLL void *H5resize_memory(void *mem, size_t size);
  842. #ifdef __cplusplus
  843. }
  844. #endif
  845. #endif /* H5public_H */