summaryrefslogtreecommitdiffstats
path: root/src/H5HG.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2000-04-04 21:00:31 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2000-04-04 21:00:31 (GMT)
commit02e4ee5edf5d1c8fe285497def5cd7b7afbf77e4 (patch)
tree4b36327c0da85d62ea116da32d0f114700d0f6c9 /src/H5HG.c
parent7170bbbc96f2b29f42be53f8271fc359f617e09c (diff)
downloadhdf5-02e4ee5edf5d1c8fe285497def5cd7b7afbf77e4.zip
hdf5-02e4ee5edf5d1c8fe285497def5cd7b7afbf77e4.tar.gz
hdf5-02e4ee5edf5d1c8fe285497def5cd7b7afbf77e4.tar.bz2
[svn-r2073] Added free-list code to the library and took out the older "temporary buffer"
code, since the functionality was superceded. See the followup document for details on the free-list code.
Diffstat (limited to 'src/H5HG.c')
-rw-r--r--src/H5HG.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/src/H5HG.c b/src/H5HG.c
index bcf0939..5d6ebe3 100644
--- a/src/H5HG.c
+++ b/src/H5HG.c
@@ -27,6 +27,7 @@
#include <H5private.h> /*library */
#include <H5ACprivate.h> /*caching */
#include <H5Eprivate.h> /*error handling */
+#include <H5FLprivate.h> /*Free Lists */
#include <H5HGprivate.h> /*global heaps */
#include <H5MFprivate.h> /*file memory management */
#include <H5MMprivate.h> /*core memory management */
@@ -68,6 +69,15 @@ static const H5AC_class_t H5AC_GHEAP[1] = {{
static intn interface_initialize_g = 0;
#define INTERFACE_INIT NULL
+/* Declare a free list to manage the H5HG_t struct */
+H5FL_DEFINE_STATIC(H5HG_heap_t);
+
+/* Declare a free list to manage arrays of H5HG_obj_t's */
+H5FL_ARR_DEFINE_STATIC(H5HG_obj_t,-1);
+
+/* Declare a PQ free list to manage heap chunks */
+H5FL_BLK_DEFINE_STATIC(heap_chunk);
+
/*-------------------------------------------------------------------------
* Function: H5HG_create
@@ -111,19 +121,19 @@ H5HG_create (H5F_t *f, size_t size)
HGOTO_ERROR (H5E_HEAP, H5E_CANTINIT, NULL,
"unable to allocate file space for global heap");
}
- if (NULL==(heap = H5MM_calloc (sizeof(H5HG_heap_t)))) {
+ if (NULL==(heap = H5FL_ALLOC (H5HG_heap_t,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
heap->addr = addr;
heap->size = size;
heap->dirty = TRUE;
- if (NULL==(heap->chunk = H5MM_malloc (size))) {
+ if (NULL==(heap->chunk = H5FL_BLK_ALLOC (heap_chunk,size,0))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
heap->nalloc = H5HG_NOBJS (f, size);
- if (NULL==(heap->obj = H5MM_calloc (heap->nalloc*sizeof(H5HG_obj_t)))) {
+ if (NULL==(heap->obj = H5FL_ARR_ALLOC (H5HG_obj_t,heap->nalloc,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -182,9 +192,9 @@ H5HG_create (H5F_t *f, size_t size)
done:
if (!ret_value && heap) {
- H5MM_xfree (heap->chunk);
- H5MM_xfree (heap->obj);
- H5MM_xfree (heap);
+ H5FL_BLK_FREE(heap_chunk,heap->chunk);
+ H5FL_ARR_FREE (H5HG_obj_t,heap->obj);
+ H5FL_FREE (H5HG_heap_t,heap);
}
FUNC_LEAVE (ret_value);
}
@@ -226,12 +236,12 @@ H5HG_load (H5F_t *f, haddr_t addr, const void UNUSED *udata1,
assert (!udata2);
/* Read the initial 4k page */
- if (NULL==(heap = H5MM_calloc (sizeof(H5HG_heap_t)))) {
+ if (NULL==(heap = H5FL_ALLOC (H5HG_heap_t,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
heap->addr = addr;
- if (NULL==(heap->chunk = H5MM_malloc (H5HG_MINSIZE))) {
+ if (NULL==(heap->chunk = H5FL_BLK_ALLOC (heap_chunk,H5HG_MINSIZE,0))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -267,7 +277,7 @@ H5HG_load (H5F_t *f, haddr_t addr, const void UNUSED *udata1,
*/
if (heap->size > H5HG_MINSIZE) {
haddr_t next_addr = addr + (hsize_t)H5HG_MINSIZE;
- if (NULL==(heap->chunk = H5MM_realloc (heap->chunk, heap->size))) {
+ if (NULL==(heap->chunk = H5FL_BLK_REALLOC (heap_chunk, heap->chunk, heap->size))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -281,7 +291,7 @@ H5HG_load (H5F_t *f, haddr_t addr, const void UNUSED *udata1,
/* Decode each object */
p = heap->chunk + H5HG_SIZEOF_HDR (f);
nalloc = H5HG_NOBJS (f, heap->size);
- if (NULL==(heap->obj = H5MM_calloc (nalloc*sizeof(H5HG_obj_t)))) {
+ if (NULL==(heap->obj = H5FL_ARR_ALLOC (H5HG_obj_t,nalloc,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -358,9 +368,9 @@ H5HG_load (H5F_t *f, haddr_t addr, const void UNUSED *udata1,
done:
if (!ret_value && heap) {
- H5MM_xfree (heap->chunk);
- H5MM_xfree (heap->obj);
- H5MM_xfree (heap);
+ H5FL_BLK_FREE (heap_chunk,heap->chunk);
+ H5FL_ARR_FREE(H5HG_obj_t,heap->obj);
+ H5FL_FREE (H5HG_heap_t,heap);
}
FUNC_LEAVE (ret_value);
}
@@ -405,17 +415,17 @@ H5HG_flush (H5F_t *f, hbool_t destroy, haddr_t addr, H5HG_heap_t *heap)
}
if (destroy) {
- for (i=0; i<f->shared->ncwfs; i++) {
- if (f->shared->cwfs[i]==heap) {
- f->shared->ncwfs -= 1;
- HDmemmove (f->shared->cwfs+i, f->shared->cwfs+i+1,
- (f->shared->ncwfs-i) * sizeof(H5HG_heap_t*));
- break;
- }
- }
- heap->chunk = H5MM_xfree (heap->chunk);
- heap->obj = H5MM_xfree (heap->obj);
- H5MM_xfree (heap);
+ for (i=0; i<f->shared->ncwfs; i++) {
+ if (f->shared->cwfs[i]==heap) {
+ f->shared->ncwfs -= 1;
+ HDmemmove (f->shared->cwfs+i, f->shared->cwfs+i+1,
+ (f->shared->ncwfs-i) * sizeof(H5HG_heap_t*));
+ break;
+ }
+ }
+ heap->chunk = H5FL_BLK_FREE(heap_chunk,heap->chunk);
+ heap->obj = H5FL_ARR_FREE(H5HG_obj_t,heap->obj);
+ H5FL_FREE (H5HG_heap_t,heap);
}
FUNC_LEAVE (SUCCEED);