summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2000-08-16 20:13:02 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2000-08-16 20:13:02 (GMT)
commit1d54c2ad20754f7c4c05ef58dd4f15c773ddca89 (patch)
tree21dd94f4a6eabf3c29862a3fdb673e06acb6ce00 /src
parent4cd9c205ec2a7f2d216b2542c631840f5a24ebe0 (diff)
downloadhdf5-1d54c2ad20754f7c4c05ef58dd4f15c773ddca89.zip
hdf5-1d54c2ad20754f7c4c05ef58dd4f15c773ddca89.tar.gz
hdf5-1d54c2ad20754f7c4c05ef58dd4f15c773ddca89.tar.bz2
[svn-r2476] Added free lists to track various data structures in memory, to reduce malloc
abuse.
Diffstat (limited to 'src')
-rw-r--r--src/H5AC.c54
-rw-r--r--src/H5ACprivate.h1
-rw-r--r--src/H5Distore.c8
-rw-r--r--src/H5F.c24
-rw-r--r--src/H5FDsec2.c8
-rw-r--r--src/H5Fistore.c8
-rw-r--r--src/H5G.c20
-rw-r--r--src/H5HL.c62
-rw-r--r--src/H5Ostab.c42
9 files changed, 160 insertions, 67 deletions
diff --git a/src/H5AC.c b/src/H5AC.c
index deb9775..290938b 100644
--- a/src/H5AC.c
+++ b/src/H5AC.c
@@ -26,6 +26,7 @@
#include <H5private.h>
#include <H5ACprivate.h>
#include <H5Eprivate.h>
+#include <H5FLprivate.h> /*Free Lists */
#include <H5MMprivate.h>
/*
@@ -44,6 +45,21 @@ static intn interface_initialize_g = 0;
#ifdef H5AC_SORT_BY_ADDR
static H5AC_t *current_cache_g = NULL; /*for sorting */
#endif
+
+/* Declare a free list to manage the H5AC_t struct */
+H5FL_DEFINE_STATIC(H5AC_t);
+
+/* Declare a PQ free list to manage the cache mapping array information */
+H5FL_ARR_DEFINE_STATIC(intn,-1);
+
+/* Declare a PQ free list to manage the cache slot array information */
+H5FL_ARR_DEFINE_STATIC(H5AC_info_ptr_t,-1);
+
+#ifdef H5AC_DEBUG
+/* Declare a PQ free list to manage the protected slot array information */
+H5FL_ARR_DEFINE_STATIC(H5AC_prot_t,-1);
+#endif /* H5AC_DEBUG */
+
/*-------------------------------------------------------------------------
* Function: H5AC_create
@@ -75,20 +91,20 @@ H5AC_create(H5F_t *f, intn size_hint)
assert(NULL == f->shared->cache);
if (size_hint < 1) size_hint = H5AC_NSLOTS;
- if (NULL==(f->shared->cache = cache = H5MM_calloc(sizeof(H5AC_t)))) {
+ if (NULL==(f->shared->cache = cache = H5FL_ALLOC(H5AC_t,1))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
cache->nslots = size_hint;
- cache->slot = H5MM_calloc(cache->nslots*sizeof(H5AC_info_t *));
+ cache->slot = H5FL_ARR_ALLOC(H5AC_info_ptr_t,cache->nslots,1);
if (NULL==cache->slot) {
- f->shared->cache = H5MM_xfree (f->shared->cache);
+ f->shared->cache = H5FL_FREE (H5AC_t,f->shared->cache);
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
}
#ifdef H5AC_DEBUG
- if ((cache->prot = H5MM_calloc(cache->nslots*sizeof(H5AC_prot_t)))==NULL) {
- cache->slot = H5MM_xfree (cache->slot);
- f->shared->cache = H5MM_xfree (f->shared->cache);
+ if ((cache->prot = H5FL_ARR_ALLOC(H5AC_prot_t,cache->nslots,1))==NULL) {
+ cache->slot = H5FL_ARR_FREE (H5AC_info_ptr_t,cache->slot);
+ f->shared->cache = H5FL_FREE (H5AC_t,f->shared->cache);
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
}
#endif /* H5AC_DEBUG */
@@ -135,13 +151,13 @@ H5AC_dest(H5F_t *f)
cache->prot[i].aprots = 0;
cache->prot[i].nprots = 0;
}
- cache->prot = H5MM_xfree(cache->prot);
+ cache->prot = H5FL_ARR_FREE(H5AC_prot_t,cache->prot);
}
#endif
- cache->slot = H5MM_xfree(cache->slot);
+ cache->slot = H5FL_ARR_FREE(H5AC_info_ptr_t,cache->slot);
cache->nslots = 0;
- f->shared->cache = cache = H5MM_xfree(cache);
+ f->shared->cache = cache = H5FL_FREE(H5AC_t,cache);
FUNC_LEAVE(SUCCEED);
}
@@ -375,7 +391,9 @@ H5AC_flush(H5F_t *f, const H5AC_class_t *type, haddr_t addr, hbool_t destroy)
herr_t status;
H5AC_flush_func_t flush=NULL;
H5AC_info_t **info;
+#ifdef H5AC_SORT_BY_ADDR
intn *map = NULL;
+#endif /* H5AC_SORT_BY_ADDR */
uintn nslots;
H5AC_t *cache = NULL;
@@ -392,7 +410,7 @@ H5AC_flush(H5F_t *f, const H5AC_class_t *type, haddr_t addr, hbool_t destroy)
* Sort the cache entries by address since flushing them in
* ascending order by address may be much more efficient.
*/
- if (NULL==(map=H5MM_malloc(cache->nslots * sizeof(intn)))) {
+ if (NULL==(map=H5FL_ARR_ALLOC(intn,cache->nslots,0))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
@@ -409,9 +427,9 @@ H5AC_flush(H5F_t *f, const H5AC_class_t *type, haddr_t addr, hbool_t destroy)
assert(H5F_addr_lt(cache->slot[i - 1]->addr, cache->slot[i]->addr));
}
#endif
-#else
+#else /* H5AC_SORT_BY_ADDR */
nslots = cache->nslots;
-#endif
+#endif /* H5AC_SORT_BY_ADDR */
/*
* Look at all cache entries.
@@ -421,18 +439,20 @@ H5AC_flush(H5F_t *f, const H5AC_class_t *type, haddr_t addr, hbool_t destroy)
info = cache->slot + map[i];
if (NULL == (*info))
break; /*the rest are empty */
-#else
+#else /* H5AC_SORT_BY_ADDR */
info = cache->slot + i;
if (NULL == (*info))
continue;
-#endif
+#endif /* H5AC_SORT_BY_ADDR */
if (!type || type == (*info)->type) {
H5AC_subid_t type_id=(*info)->type->id; /* Remember this for later */
flush = (*info)->type->flush;
status = (flush)(f, destroy, (*info)->addr, (*info));
if (status < 0) {
- map = H5MM_xfree(map);
+#ifdef H5AC_SORT_BY_ADDR
+ map = H5FL_ARR_FREE(intn,map);
+#endif /* H5AC_SORT_BY_ADDR */
HRETURN_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL,
"unable to flush cache");
}
@@ -441,7 +461,9 @@ H5AC_flush(H5F_t *f, const H5AC_class_t *type, haddr_t addr, hbool_t destroy)
(*info)= NULL;
}
}
- map = H5MM_xfree(map);
+#ifdef H5AC_SORT_BY_ADDR
+ map = H5FL_ARR_FREE(intn,map);
+#endif /* H5AC_SORT_BY_ADDR */
/*
* If there are protected object then fail. However, everything
diff --git a/src/H5ACprivate.h b/src/H5ACprivate.h
index 7335c0d..c9d797b 100644
--- a/src/H5ACprivate.h
+++ b/src/H5ACprivate.h
@@ -82,6 +82,7 @@ typedef struct H5AC_info_t {
const H5AC_class_t *type; /*type of object stored here */
haddr_t addr; /*file address for object */
} H5AC_info_t;
+typedef H5AC_info_t *H5AC_info_ptr_t; /* Typedef for free lists */
#ifdef H5AC_DEBUG
typedef struct H5AC_prot_t {
diff --git a/src/H5Distore.c b/src/H5Distore.c
index b0f7a39..8eb107b 100644
--- a/src/H5Distore.c
+++ b/src/H5Distore.c
@@ -97,6 +97,7 @@ typedef struct H5F_rdcc_ent_t {
struct H5F_rdcc_ent_t *next;/*next item in doubly-linked list */
struct H5F_rdcc_ent_t *prev;/*previous item in doubly-linked list */
} H5F_rdcc_ent_t;
+typedef H5F_rdcc_ent_t *H5F_rdcc_ent_ptr_t; /* For free lists */
/* Private prototypes */
static size_t H5F_istore_sizeof_rkey(H5F_t *f, const void *_udata);
@@ -187,6 +188,9 @@ H5FL_BLK_DEFINE_STATIC(istore_chunk);
/* Declare a free list to manage H5F_rdcc_ent_t objects */
H5FL_DEFINE_STATIC(H5F_rdcc_ent_t);
+/* Declare a PQ free list to manage the H5F_rdcc_ent_ptr_t array information */
+H5FL_ARR_DEFINE_STATIC(H5F_rdcc_ent_ptr_t,-1);
+
/*-------------------------------------------------------------------------
* Function: H5F_istore_chunk_alloc
@@ -900,7 +904,7 @@ H5F_istore_init (H5F_t *f)
HDmemset (rdcc, 0, sizeof(H5F_rdcc_t));
if (f->shared->rdcc_nbytes>0 && f->shared->rdcc_nelmts>0) {
rdcc->nslots = f->shared->rdcc_nelmts;
- rdcc->slot = H5MM_calloc (rdcc->nslots*sizeof(H5F_rdcc_ent_t*));
+ rdcc->slot = H5FL_ARR_ALLOC (H5F_rdcc_ent_ptr_t,rdcc->nslots,1);
if (NULL==rdcc->slot) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
@@ -1177,7 +1181,7 @@ H5F_istore_dest (H5F_t *f)
"unable to flush one or more raw data chunks");
}
- H5MM_xfree (rdcc->slot);
+ H5FL_ARR_FREE (H5F_rdcc_ent_ptr_t,rdcc->slot);
HDmemset (rdcc, 0, sizeof(H5F_rdcc_t));
FUNC_LEAVE (SUCCEED);
}
diff --git a/src/H5F.c b/src/H5F.c
index b7cecfb..7c50875 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -36,6 +36,7 @@ static char RcsId[] = "@(#)$Revision$";
#include <H5private.h> /*library functions */
#include <H5Aprivate.h> /*attributes */
#include <H5Dprivate.h> /*datasets */
+#include <H5FLprivate.h> /*Free Lists */
#include <H5Iprivate.h> /*object IDs */
#include <H5ACprivate.h> /*cache */
#include <H5Eprivate.h> /*error handling */
@@ -124,6 +125,15 @@ static herr_t H5F_flush(H5F_t *f, H5F_scope_t scope, hbool_t invalidate,
static haddr_t H5F_locate_signature(H5FD_t *file);
static intn H5F_flush_all_cb(H5F_t *f, const void *_invalidate);
+/* Declare a free list to manage the H5F_t struct */
+H5FL_DEFINE_STATIC(H5F_t);
+
+/* Declare a free list to manage the H5F_file_t struct */
+H5FL_DEFINE_STATIC(H5F_file_t);
+
+/* Declare the external free list for the H5G_t struct */
+H5FL_EXTERN(H5G_t);
+
/*-------------------------------------------------------------------------
* Function: H5F_init
@@ -709,7 +719,7 @@ H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id)
FUNC_ENTER(H5F_new, NULL);
- if (NULL==(f=H5MM_calloc(sizeof(H5F_t)))) {
+ if (NULL==(f=H5FL_ALLOC(H5F_t,1))) {
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -717,7 +727,7 @@ H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id)
if (shared) {
f->shared = shared;
} else {
- f->shared = H5MM_calloc(sizeof(H5F_file_t));
+ f->shared = H5FL_ALLOC(H5F_file_t,1);
f->shared->boot_addr = HADDR_UNDEF;
f->shared->base_addr = HADDR_UNDEF;
f->shared->freespace_addr = HADDR_UNDEF;
@@ -776,8 +786,8 @@ H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id)
done:
if (!ret_value && f) {
- if (!shared) H5MM_xfree(f->shared);
- H5MM_xfree(f);
+ if (!shared) H5FL_FREE(H5F_file_t,f->shared);
+ H5FL_FREE(H5F_t,f);
}
FUNC_LEAVE(ret_value);
@@ -823,7 +833,7 @@ H5F_dest(H5F_t *f)
* Do not close the root group since we didn't count it, but free
* the memory associated with it.
*/
- H5MM_xfree(f->shared->root_grp);
+ H5FL_FREE(H5G_t,f->shared->root_grp);
f->shared->root_grp=NULL;
if (H5AC_dest(f)) {
HERROR(H5E_FILE, H5E_CANTINIT, "problems closing file");
@@ -843,7 +853,7 @@ H5F_dest(H5F_t *f)
HERROR(H5E_FILE, H5E_CANTINIT, "problems closing file");
ret_value = FAIL; /*but keep going*/
}
- f->shared = H5MM_xfree(f->shared);
+ f->shared = H5FL_FREE(H5F_file_t,f->shared);
} else if (f->shared->nrefs>0) {
/*
@@ -857,7 +867,7 @@ H5F_dest(H5F_t *f)
f->name = H5MM_xfree(f->name);
f->mtab.child = H5MM_xfree(f->mtab.child);
f->mtab.nalloc = 0;
- H5MM_xfree(f);
+ H5FL_FREE(H5F_t,f);
} else if (f && f->nrefs>0) {
/*
* There are other references to this file. Only decrement the
diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c
index 8211145..7d0a9cf 100644
--- a/src/H5FDsec2.c
+++ b/src/H5FDsec2.c
@@ -16,6 +16,7 @@
#include <H5Eprivate.h> /*error handling */
#include <H5Fprivate.h> /*files */
#include <H5FDsec2.h> /* Sec2 file driver */
+#include <H5FLprivate.h> /*Free Lists */
#include <H5MMprivate.h> /* Memory allocation */
#include <H5Pprivate.h> /*property lists */
@@ -162,6 +163,9 @@ static const H5FD_class_t H5FD_sec2_g = {
#define INTERFACE_INIT H5FD_sec2_init
static intn interface_initialize_g = 0;
+/* Declare a free list to manage the H5FD_sec2_t struct */
+H5FL_DEFINE_STATIC(H5FD_sec2_t);
+
/*-------------------------------------------------------------------------
* Function: H5FD_sec2_init
@@ -282,7 +286,7 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t UNUSED fapl_id,
}
/* Create the new file struct */
- if (NULL==(file=H5MM_calloc(sizeof(H5FD_sec2_t))))
+ if (NULL==(file=H5FL_ALLOC(H5FD_sec2_t,1)))
HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
"unable to allocate file struct");
file->fd = fd;
@@ -330,7 +334,7 @@ H5FD_sec2_close(H5FD_t *_file)
if (close(file->fd)<0)
HRETURN_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file");
- H5MM_xfree(file);
+ H5FL_FREE(H5FD_sec2_t,file);
FUNC_LEAVE(SUCCEED);
}
diff --git a/src/H5Fistore.c b/src/H5Fistore.c
index b0f7a39..8eb107b 100644
--- a/src/H5Fistore.c
+++ b/src/H5Fistore.c
@@ -97,6 +97,7 @@ typedef struct H5F_rdcc_ent_t {
struct H5F_rdcc_ent_t *next;/*next item in doubly-linked list */
struct H5F_rdcc_ent_t *prev;/*previous item in doubly-linked list */
} H5F_rdcc_ent_t;
+typedef H5F_rdcc_ent_t *H5F_rdcc_ent_ptr_t; /* For free lists */
/* Private prototypes */
static size_t H5F_istore_sizeof_rkey(H5F_t *f, const void *_udata);
@@ -187,6 +188,9 @@ H5FL_BLK_DEFINE_STATIC(istore_chunk);
/* Declare a free list to manage H5F_rdcc_ent_t objects */
H5FL_DEFINE_STATIC(H5F_rdcc_ent_t);
+/* Declare a PQ free list to manage the H5F_rdcc_ent_ptr_t array information */
+H5FL_ARR_DEFINE_STATIC(H5F_rdcc_ent_ptr_t,-1);
+
/*-------------------------------------------------------------------------
* Function: H5F_istore_chunk_alloc
@@ -900,7 +904,7 @@ H5F_istore_init (H5F_t *f)
HDmemset (rdcc, 0, sizeof(H5F_rdcc_t));
if (f->shared->rdcc_nbytes>0 && f->shared->rdcc_nelmts>0) {
rdcc->nslots = f->shared->rdcc_nelmts;
- rdcc->slot = H5MM_calloc (rdcc->nslots*sizeof(H5F_rdcc_ent_t*));
+ rdcc->slot = H5FL_ARR_ALLOC (H5F_rdcc_ent_ptr_t,rdcc->nslots,1);
if (NULL==rdcc->slot) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
@@ -1177,7 +1181,7 @@ H5F_istore_dest (H5F_t *f)
"unable to flush one or more raw data chunks");
}
- H5MM_xfree (rdcc->slot);
+ H5FL_ARR_FREE (H5F_rdcc_ent_ptr_t,rdcc->slot);
HDmemset (rdcc, 0, sizeof(H5F_rdcc_t));
FUNC_LEAVE (SUCCEED);
}
diff --git a/src/H5G.c b/src/H5G.c
index 8ef6db5..24bd204 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -79,6 +79,7 @@
#include <H5Bprivate.h>
#include <H5Dprivate.h>
#include <H5Eprivate.h>
+#include <H5FLprivate.h> /*Free Lists */
#include <H5Gpkg.h>
#include <H5HLprivate.h>
#include <H5Iprivate.h>
@@ -98,6 +99,9 @@ static H5G_typeinfo_t *H5G_type_g = NULL; /*object typing info */
static size_t H5G_ntypes_g = 0; /*entries in type table */
static size_t H5G_atypes_g = 0; /*entries allocated */
+/* Declare a free list to manage the H5G_t struct */
+H5FL_DEFINE(H5G_t);
+
/*-------------------------------------------------------------------------
* Function: H5Gcreate
@@ -1218,7 +1222,7 @@ H5G_mkroot (H5F_t *f, H5G_entry_t *ent)
* don't count the root group as an open object. The root group will
* never be closed.
*/
- if (NULL==(f->shared->root_grp = H5MM_calloc (sizeof(H5G_t)))) {
+ if (NULL==(f->shared->root_grp = H5FL_ALLOC (H5G_t,1))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
@@ -1294,12 +1298,12 @@ H5G_create(H5G_entry_t *loc, const char *name, size_t size_hint)
}
/* create an open group */
- if (NULL==(grp = H5MM_calloc(sizeof(H5G_t)))) {
+ if (NULL==(grp = H5FL_ALLOC(H5G_t,1))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
if (H5G_stab_create(grp_ent.file, size_hint, &(grp->ent)/*out*/) < 0) {
- grp = H5MM_xfree(grp);
+ grp = H5FL_FREE(H5G_t,grp);
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, NULL, "can't create grp");
}
@@ -1309,7 +1313,7 @@ H5G_create(H5G_entry_t *loc, const char *name, size_t size_hint)
}
if (H5G_stab_insert(&grp_ent, rest, &(grp->ent)) < 0) {
H5O_close(&(grp->ent));
- grp = H5MM_xfree(grp);
+ grp = H5FL_FREE(H5G_t,grp);
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, NULL, "can't insert");
}
grp->nref = 1;
@@ -1395,7 +1399,7 @@ H5G_open(H5G_entry_t *loc, const char *name)
done:
if (!ret_value && grp) {
- H5MM_xfree(grp);
+ H5FL_FREE(H5G_t,grp);
}
FUNC_LEAVE(ret_value);
}
@@ -1431,7 +1435,7 @@ H5G_open_oid(H5G_entry_t *ent)
assert(ent);
/* Open the object, making sure it's a group */
- if (NULL==(grp = H5MM_calloc(sizeof(H5G_t)))) {
+ if (NULL==(grp = H5FL_ALLOC(H5G_t,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -1452,7 +1456,7 @@ H5G_open_oid(H5G_entry_t *ent)
done:
if (!ret_value && grp) {
- H5MM_xfree(grp);
+ H5FL_FREE(H5G_t,grp);
}
FUNC_LEAVE(ret_value);
}
@@ -1517,7 +1521,7 @@ H5G_close(H5G_t *grp)
HRETURN_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to close");
}
grp->nref = 0;
- H5MM_xfree (grp);
+ H5FL_FREE (H5G_t,grp);
} else {
--grp->nref;
}
diff --git a/src/H5HL.c b/src/H5HL.c
index b90a9db..99c57da 100644
--- a/src/H5HL.c
+++ b/src/H5HL.c
@@ -22,6 +22,7 @@
#include <H5ACprivate.h> /*cache */
#include <H5Eprivate.h> /*error handling */
#include <H5Fprivate.h> /*file access */
+#include <H5FLprivate.h> /*Free Lists */
#include <H5HLprivate.h> /*self */
#include <H5MFprivate.h> /*file memory management */
#include <H5MMprivate.h> /*core memory management */
@@ -68,6 +69,15 @@ static const H5AC_class_t H5AC_LHEAP[1] = {{
static intn interface_initialize_g = 0;
#define INTERFACE_INIT NULL
+/* Declare a free list to manage the H5HL_free_t struct */
+H5FL_DEFINE_STATIC(H5HL_free_t);
+
+/* Declare a free list to manage the H5HL_t struct */
+H5FL_DEFINE_STATIC(H5HL_t);
+
+/* Declare a PQ free list to manage the heap chunk information */
+H5FL_BLK_DEFINE_STATIC(heap_chunk);
+
/*-------------------------------------------------------------------------
* Function: H5HL_create
@@ -122,21 +132,21 @@ H5HL_create(H5F_t *f, size_t size_hint, haddr_t *addr_p/*out*/)
}
/* allocate memory version */
- if (NULL==(heap = H5MM_calloc(sizeof(H5HL_t)))) {
+ if (NULL==(heap = H5FL_ALLOC(H5HL_t,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
heap->addr = *addr_p + (hsize_t)H5HL_SIZEOF_HDR(f);
heap->disk_alloc = size_hint;
heap->mem_alloc = size_hint;
- if (NULL==(heap->chunk = H5MM_calloc(H5HL_SIZEOF_HDR(f) + size_hint))) {
+ if (NULL==(heap->chunk = H5FL_BLK_ALLOC(heap_chunk,H5HL_SIZEOF_HDR(f) + size_hint,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
/* free list */
if (size_hint) {
- if (NULL==(heap->freelist = H5MM_malloc(sizeof(H5HL_free_t)))) {
+ if (NULL==(heap->freelist = H5FL_ALLOC(H5HL_free_t,0))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
@@ -161,9 +171,9 @@ H5HL_create(H5F_t *f, size_t size_hint, haddr_t *addr_p/*out*/)
H5MF_xfree(f, H5FD_MEM_LHEAP, *addr_p, total_size);
}
if (heap) {
- H5MM_xfree (heap->chunk);
- H5MM_xfree (heap->freelist);
- H5MM_xfree (heap);
+ H5FL_BLK_FREE (heap_chunk,heap->chunk);
+ H5FL_FREE (H5HL_free_t,heap->freelist);
+ H5FL_FREE (H5HL_t,heap);
}
}
FUNC_LEAVE(ret_value);
@@ -213,7 +223,7 @@ H5HL_load(H5F_t *f, haddr_t addr, const void UNUSED *udata1,
"unable to read heap header");
}
p = hdr;
- if (NULL==(heap = H5MM_calloc(sizeof(H5HL_t)))) {
+ if (NULL==(heap = H5FL_ALLOC(H5HL_t,1))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -241,7 +251,7 @@ H5HL_load(H5F_t *f, haddr_t addr, const void UNUSED *udata1,
/* data */
H5F_addr_decode(f, &p, &(heap->addr));
- heap->chunk = H5MM_calloc(H5HL_SIZEOF_HDR(f) + heap->mem_alloc);
+ heap->chunk = H5FL_BLK_ALLOC(heap_chunk,H5HL_SIZEOF_HDR(f) + heap->mem_alloc,1);
if (NULL==heap->chunk) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
@@ -259,7 +269,7 @@ H5HL_load(H5F_t *f, haddr_t addr, const void UNUSED *udata1,
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, NULL,
"bad heap free list");
}
- if (NULL==(fl = H5MM_malloc(sizeof(H5HL_free_t)))) {
+ if (NULL==(fl = H5FL_ALLOC(H5HL_free_t,0))) {
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -284,12 +294,12 @@ H5HL_load(H5F_t *f, haddr_t addr, const void UNUSED *udata1,
done:
if (!ret_value && heap) {
- heap->chunk = H5MM_xfree(heap->chunk);
- H5MM_xfree(heap);
- for (fl = heap->freelist; fl; fl = tail) {
- tail = fl->next;
- H5MM_xfree(fl);
- }
+ heap->chunk = H5FL_BLK_FREE(heap_chunk,heap->chunk);
+ for (fl = heap->freelist; fl; fl = tail) {
+ tail = fl->next;
+ H5FL_FREE(H5HL_free_t,fl);
+ }
+ H5FL_FREE(H5HL_t,heap);
}
FUNC_LEAVE(ret_value);
}
@@ -420,13 +430,13 @@ H5HL_flush(H5F_t *f, hbool_t destroy, haddr_t addr, H5HL_t *heap)
* Should we destroy the memory version?
*/
if (destroy) {
- heap->chunk = H5MM_xfree(heap->chunk);
- while (heap->freelist) {
- fl = heap->freelist;
- heap->freelist = fl->next;
- H5MM_xfree(fl);
- }
- H5MM_xfree(heap);
+ heap->chunk = H5FL_BLK_FREE(heap_chunk,heap->chunk);
+ while (heap->freelist) {
+ fl = heap->freelist;
+ heap->freelist = fl->next;
+ H5FL_FREE(H5HL_free_t,fl);
+ }
+ H5FL_FREE(H5HL_t,heap);
}
FUNC_LEAVE(SUCCEED);
}
@@ -560,7 +570,7 @@ H5HL_remove_free(H5HL_t *heap, H5HL_free_t *fl)
if (fl->next) fl->next->prev = fl->prev;
if (!fl->prev) heap->freelist = fl->next;
- return H5MM_xfree(fl);
+ return H5FL_FREE(H5HL_free_t,fl);
}
/*-------------------------------------------------------------------------
@@ -677,7 +687,7 @@ H5HL_insert(H5F_t *f, haddr_t addr, size_t buf_size, const void *buf)
*/
offset = heap->mem_alloc;
if (need_more - need_size >= H5HL_SIZEOF_FREE(f)) {
- if (NULL==(fl = H5MM_malloc(sizeof(H5HL_free_t)))) {
+ if (NULL==(fl = H5FL_ALLOC(H5HL_free_t,0))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, (size_t)(-1),
"memory allocation failed");
}
@@ -708,7 +718,7 @@ H5HL_insert(H5F_t *f, haddr_t addr, size_t buf_size, const void *buf)
#endif
old_size = heap->mem_alloc;
heap->mem_alloc += need_more;
- heap->chunk = H5MM_realloc(heap->chunk,
+ heap->chunk = H5FL_BLK_REALLOC(heap_chunk,heap->chunk,
H5HL_SIZEOF_HDR(f) + heap->mem_alloc);
if (NULL==heap->chunk) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, (size_t)(-1),
@@ -893,7 +903,7 @@ H5HL_remove(H5F_t *f, haddr_t addr, size_t offset, size_t size)
/*
* Add an entry to the free list.
*/
- if (NULL==(fl = H5MM_malloc(sizeof(H5HL_free_t)))) {
+ if (NULL==(fl = H5FL_ALLOC(H5HL_free_t,0))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
diff --git a/src/H5Ostab.c b/src/H5Ostab.c
index a2af9ed..87188fb 100644
--- a/src/H5Ostab.c
+++ b/src/H5Ostab.c
@@ -16,6 +16,7 @@
*/
#include <H5private.h>
#include <H5Eprivate.h>
+#include <H5FLprivate.h> /*Free Lists */
#include <H5Gprivate.h>
#include <H5MMprivate.h>
#include <H5Oprivate.h>
@@ -27,6 +28,7 @@ static void *H5O_stab_decode(H5F_t *f, const uint8_t *p, H5O_shared_t *sh);
static herr_t H5O_stab_encode(H5F_t *f, uint8_t *p, const void *_mesg);
static void *H5O_stab_copy(const void *_mesg, void *_dest);
static size_t H5O_stab_size(H5F_t *f, const void *_mesg);
+static herr_t H5O_stab_free (void *_mesg);
static herr_t H5O_stab_debug(H5F_t *f, const void *_mesg,
FILE * stream, intn indent, intn fwidth);
@@ -40,7 +42,7 @@ const H5O_class_t H5O_STAB[1] = {{
H5O_stab_copy, /*copy the native value */
H5O_stab_size, /*size of symbol table entry */
NULL, /*default reset method */
- NULL, /*default free method */
+ H5O_stab_free, /* free method */
NULL, /*get share method */
NULL, /*set share method */
H5O_stab_debug, /*debug the message */
@@ -49,6 +51,10 @@ const H5O_class_t H5O_STAB[1] = {{
/* Interface initialization */
static intn interface_initialize_g = 0;
#define INTERFACE_INIT NULL
+
+/* Declare a free list to manage the H5O_stab_t struct */
+H5FL_DEFINE_STATIC(H5O_stab_t);
+
/*-------------------------------------------------------------------------
* Function: H5O_stab_decode
@@ -81,7 +87,7 @@ H5O_stab_decode(H5F_t *f, const uint8_t *p, H5O_shared_t UNUSED *sh)
assert (!sh);
/* decode */
- if (NULL==(stab = H5MM_calloc(sizeof(H5O_stab_t)))) {
+ if (NULL==(stab = H5FL_ALLOC(H5O_stab_t,1))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -158,7 +164,7 @@ H5O_stab_fast(const H5G_cache_t *cache, const H5O_class_t *type, void *_mesg)
if (H5O_STAB == type) {
if (_mesg) {
stab = (H5O_stab_t *) _mesg;
- } else if (NULL==(stab = H5MM_calloc(sizeof(H5O_stab_t)))) {
+ } else if (NULL==(stab = H5FL_ALLOC(H5O_stab_t,1))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -196,7 +202,7 @@ H5O_stab_copy(const void *_mesg, void *_dest)
/* check args */
assert(stab);
- if (!dest && NULL==(dest = H5MM_calloc(sizeof(H5O_stab_t)))) {
+ if (!dest && NULL==(dest = H5FL_ALLOC(H5O_stab_t,1))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
@@ -232,6 +238,34 @@ H5O_stab_size(H5F_t *f, const void UNUSED *_mesg)
FUNC_ENTER(H5O_stab_size, 0);
FUNC_LEAVE(2 * H5F_SIZEOF_ADDR(f));
}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5O_stab_free
+ *
+ * Purpose: Free's the message
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, March 30, 2000
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5O_stab_free (void *mesg)
+{
+ FUNC_ENTER (H5O_stab_free, FAIL);
+
+ assert (mesg);
+
+ H5FL_FREE(H5O_stab_t,mesg);
+
+ FUNC_LEAVE (SUCCEED);
+}
+
/*-------------------------------------------------------------------------
* Function: H5O_stab_debug