summaryrefslogtreecommitdiffstats
path: root/src/H5B.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/H5B.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/H5B.c')
-rw-r--r--src/H5B.c72
1 files changed, 44 insertions, 28 deletions
diff --git a/src/H5B.c b/src/H5B.c
index 47a6e15..acb3079 100644
--- a/src/H5B.c
+++ b/src/H5B.c
@@ -92,6 +92,7 @@
#include <H5Bprivate.h> /*B-link trees */
#include <H5Eprivate.h> /*error handling */
#include <H5Fprivate.h> /*file access */
+#include <H5FLprivate.h> /*Free Lists */
#include <H5MFprivate.h> /*file memory management */
#include <H5MMprivate.h> /*core memory management */
#include <H5Pprivate.h> /*property lists */
@@ -141,6 +142,21 @@ static const H5AC_class_t H5AC_BT[1] = {{
#define INTERFACE_INIT NULL
static intn interface_initialize_g = 0;
+/* Declare a free list to manage the page information */
+H5FL_BLK_DEFINE_STATIC(page);
+
+/* Declare a PQ free list to manage the native block information */
+H5FL_BLK_DEFINE_STATIC(native_block);
+
+/* Declare a free list to manage the H5B_key_t array information */
+H5FL_ARR_DEFINE_STATIC(H5B_key_t,-1);
+
+/* Declare a free list to manage the haddr_t array information */
+H5FL_ARR_DEFINE_STATIC(haddr_t,-1);
+
+/* Declare a free list to manage the H5B_t struct */
+H5FL_DEFINE_STATIC(H5B_t);
+
/*-------------------------------------------------------------------------
* Function: H5B_create
@@ -194,7 +210,7 @@ H5B_create(H5F_t *f, const H5B_class_t *type, void *udata,
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
"file allocation failed for B-tree root node");
}
- if (NULL==(bt = H5MM_calloc(sizeof(H5B_t)))) {
+ if (NULL==(bt = H5FL_ALLOC(H5B_t,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed for B-tree root node");
}
@@ -207,10 +223,10 @@ H5B_create(H5F_t *f, const H5B_class_t *type, void *udata,
bt->left = HADDR_UNDEF;
bt->right = HADDR_UNDEF;
bt->nchildren = 0;
- if (NULL==(bt->page=H5MM_calloc(size)) ||
- NULL==(bt->native=H5MM_malloc(total_native_keysize)) ||
- NULL==(bt->child=H5MM_malloc(2*H5B_K(f,type)*sizeof(haddr_t))) ||
- NULL==(bt->key=H5MM_malloc((2*H5B_K(f,type)+1)*sizeof(H5B_key_t)))) {
+ if (NULL==(bt->page=H5FL_BLK_ALLOC(page,size,1)) ||
+ NULL==(bt->native=H5FL_BLK_ALLOC(native_block,total_native_keysize,0)) ||
+ NULL==(bt->child=H5FL_ARR_ALLOC(haddr_t,2*H5B_K(f,type),0)) ||
+ NULL==(bt->key=H5FL_ARR_ALLOC(H5B_key_t,(2*H5B_K(f,type)+1),0))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed for B-tree root node");
}
@@ -253,11 +269,11 @@ H5B_create(H5F_t *f, const H5B_class_t *type, void *udata,
if (ret_value<0) {
H5MF_xfree(f, H5FD_MEM_BTREE, *addr_p, size);
if (bt) {
- H5MM_xfree (bt->page);
- H5MM_xfree (bt->native);
- H5MM_xfree (bt->child);
- H5MM_xfree (bt->key);
- H5MM_xfree (bt);
+ H5FL_BLK_FREE (page,bt->page);
+ H5FL_BLK_FREE (native_block,bt->native);
+ H5FL_ARR_FREE (haddr_t,bt->child);
+ H5FL_ARR_FREE (H5B_key_t,bt->key);
+ H5FL_FREE (H5B_t,bt);
}
}
@@ -301,7 +317,7 @@ H5B_load(H5F_t *f, haddr_t addr, const void *_type, void *udata)
assert(type);
assert(type->get_sizeof_rkey);
- if (NULL==(bt = H5MM_calloc(sizeof(H5B_t)))) {
+ if (NULL==(bt = H5FL_ALLOC(H5B_t,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -310,10 +326,10 @@ H5B_load(H5F_t *f, haddr_t addr, const void *_type, void *udata)
bt->type = type;
bt->dirty = FALSE;
bt->ndirty = 0;
- if (NULL==(bt->page=H5MM_malloc(size)) ||
- NULL==(bt->native=H5MM_malloc(total_nkey_size)) ||
- NULL==(bt->key=H5MM_malloc((2*H5B_K(f,type)+1)*sizeof(H5B_key_t))) ||
- NULL==(bt->child=H5MM_malloc(2*H5B_K(f,type)*sizeof(haddr_t)))) {
+ if (NULL==(bt->page=H5FL_BLK_ALLOC(page,size,0)) ||
+ NULL==(bt->native=H5FL_BLK_ALLOC(native_block,total_nkey_size,0)) ||
+ NULL==(bt->key=H5FL_ARR_ALLOC(H5B_key_t,(2*H5B_K(f,type)+1),0)) ||
+ NULL==(bt->child=H5FL_ARR_ALLOC(haddr_t,2*H5B_K(f,type),0))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -367,11 +383,11 @@ H5B_load(H5F_t *f, haddr_t addr, const void *_type, void *udata)
done:
if (!ret_value && bt) {
- H5MM_xfree(bt->child);
- H5MM_xfree(bt->key);
- H5MM_xfree(bt->page);
- H5MM_xfree(bt->native);
- H5MM_xfree(bt);
+ H5FL_ARR_FREE(haddr_t,bt->child);
+ H5FL_ARR_FREE(H5B_key_t,bt->key);
+ H5FL_BLK_FREE(page,bt->page);
+ H5FL_BLK_FREE(native_block,bt->native);
+ H5FL_FREE(H5B_t,bt);
}
FUNC_LEAVE(ret_value);
}
@@ -474,11 +490,11 @@ H5B_flush(H5F_t *f, hbool_t destroy, haddr_t addr, H5B_t *bt)
bt->ndirty = 0;
}
if (destroy) {
- H5MM_xfree(bt->child);
- H5MM_xfree(bt->key);
- H5MM_xfree(bt->page);
- H5MM_xfree(bt->native);
- H5MM_xfree(bt);
+ H5FL_ARR_FREE(haddr_t,bt->child);
+ H5FL_ARR_FREE(H5B_key_t,bt->key);
+ H5FL_BLK_FREE(page,bt->page);
+ H5FL_BLK_FREE(native_block,bt->native);
+ H5FL_FREE(H5B_t,bt);
}
FUNC_LEAVE(SUCCEED);
}
@@ -1542,7 +1558,7 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata)
* We've reached the left-most leaf. Now follow the right-sibling
* pointer from leaf to leaf until we've processed all leaves.
*/
- if (NULL==(child=H5MM_malloc(2*H5B_K(f,type)*sizeof(haddr_t))) ||
+ if (NULL==(child=H5FL_ARR_ALLOC(haddr_t,2*H5B_K(f,type),0)) ||
NULL==(key=H5MM_malloc((2*H5B_K(f, type)+1)*type->sizeof_nkey))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
@@ -1587,8 +1603,8 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata)
}
}
- done:
- H5MM_xfree(child);
+done:
+ H5FL_ARR_FREE(haddr_t,child);
H5MM_xfree(key);
FUNC_LEAVE(ret_value);
}