summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-04-08 03:46:48 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-04-08 03:46:48 (GMT)
commit13ca97618db62034fa78b8d87f7160cb2a1f4bfc (patch)
tree08409d4a9670de57059d50e7dc4790d7d88ded43
parentd4ab501d637389fc8f6dbae8ab12c6e032b19dfd (diff)
downloadhdf5-13ca97618db62034fa78b8d87f7160cb2a1f4bfc.zip
hdf5-13ca97618db62034fa78b8d87f7160cb2a1f4bfc.tar.gz
hdf5-13ca97618db62034fa78b8d87f7160cb2a1f4bfc.tar.bz2
[svn-r10580] Purpose:
Code optimization Description: Add "base" size to array free list code, to accomodate skip list nodes. Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti)
-rw-r--r--src/H5FL.c6
-rw-r--r--src/H5FLprivate.h33
-rw-r--r--src/H5SL.c13
3 files changed, 32 insertions, 20 deletions
diff --git a/src/H5FL.c b/src/H5FL.c
index 4b39fd9..40483c8 100644
--- a/src/H5FL.c
+++ b/src/H5FL.c
@@ -1275,8 +1275,8 @@ H5FL_arr_init(H5FL_arr_head_t *head)
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
/* Initialize the size of each array */
- for(u=1; u<(size_t)head->maxelem; u++)
- head->list_arr[u].size=head->size*u;
+ for(u = 0; u<(size_t)head->maxelem; u++)
+ head->list_arr[u].size = head->base_size + (head->elem_size * u);
/* Indicate that the free list is initialized */
head->init=1;
@@ -1521,7 +1521,7 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void * obj, size_t new_elem)
ret_value=H5FL_arr_malloc(head,new_elem);
/* Copy the appropriate amount of elements */
- blk_size=head->size*MIN(temp->nelem,new_elem);
+ blk_size = head->list_arr[ MIN(temp->nelem, new_elem) ].size;
HDmemcpy(ret_value,obj,blk_size);
/* Free the old block */
diff --git a/src/H5FLprivate.h b/src/H5FLprivate.h
index 88c179b..ba26146 100644
--- a/src/H5FLprivate.h
+++ b/src/H5FLprivate.h
@@ -201,7 +201,8 @@ typedef struct H5FL_arr_head_t {
size_t list_mem; /* Amount of memory in block on free list */
const char *name; /* Name of the type */
int maxelem; /* Maximum number of elements in an array */
- size_t size; /* Size of the array elements in the list */
+ size_t base_size; /* Size of the "base" object in the list */
+ size_t elem_size; /* Size of the array elements in the list */
H5FL_arr_node_t *list_arr; /* Array of lists of free blocks */
} H5FL_arr_head_t;
@@ -211,16 +212,22 @@ typedef struct H5FL_arr_head_t {
#define H5FL_ARR_NAME(t) H5_##t##_arr_free_list
#ifndef H5_NO_ARR_FREE_LISTS
/* Common macro for H5FL_BLK_DEFINE & H5FL_BLK_DEFINE_STATIC */
-#define H5FL_ARR_DEFINE_COMMON(t,m) H5FL_arr_head_t H5FL_ARR_NAME(t)={0,0,0,#t"_arr",m+1,sizeof(t),NULL}
+#define H5FL_ARR_DEFINE_COMMON(b,t,m) H5FL_arr_head_t H5FL_ARR_NAME(t)={0,0,0,#t"_arr",m+1,b,sizeof(t),NULL}
/* Declare a free list to manage arrays of type 't' */
-#define H5FL_ARR_DEFINE(t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(t,m)
+#define H5FL_ARR_DEFINE(t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(0,t,m)
+
+/* Declare a free list to manage base 'b' + arrays of type 't' */
+#define H5FL_BARR_DEFINE(b,t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(sizeof(b),t,m)
/* Reference a free list for arrays of type 't' defined in another file */
#define H5FL_ARR_EXTERN(t) extern H5_DLL H5FL_arr_head_t H5FL_ARR_NAME(t)
/* Declare a static free list to manage arrays of type 't' */
-#define H5FL_ARR_DEFINE_STATIC(t,m) static H5FL_ARR_DEFINE_COMMON(t,m)
+#define H5FL_ARR_DEFINE_STATIC(t,m) static H5FL_ARR_DEFINE_COMMON(0,t,m)
+
+/* Declare a static free list to manage base 'b' + arrays of type 't' */
+#define H5FL_BARR_DEFINE_STATIC(b,t,m) static H5FL_ARR_DEFINE_COMMON(sizeof(b),t,m)
/* Allocate an array of type 't' */
#define H5FL_ARR_MALLOC(t,elem) H5FL_arr_malloc(&(H5FL_ARR_NAME(t)),elem)
@@ -236,15 +243,17 @@ typedef struct H5FL_arr_head_t {
#else /* H5_NO_ARR_FREE_LISTS */
/* Common macro for H5FL_ARR_DEFINE & H5FL_ARR_DEFINE_STATIC */
-#define H5FL_ARR_DEFINE_COMMON(t,m) int H5FL_ARR_NAME(t)
-
-#define H5FL_ARR_DEFINE(t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(t,m)
-#define H5FL_ARR_EXTERN(t) extern H5_DLL int H5FL_ARR_NAME(t)
-#define H5FL_ARR_DEFINE_STATIC(t,m) static H5FL_ARR_DEFINE_COMMON(t,m)
-#define H5FL_ARR_MALLOC(t,elem) H5MM_malloc((elem)*sizeof(t))
-#define H5FL_ARR_CALLOC(t,elem) H5MM_calloc((elem)*sizeof(t))
+#define H5FL_ARR_DEFINE_COMMON(t,m) size_t H5FL_ARR_NAME(t)
+
+#define H5FL_ARR_DEFINE(t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(t,m) = 0
+#define H5FL_BARR_DEFINE(b,t,m) H5_DLL H5FL_ARR_DEFINE_COMMON(t,m) = sizeof(b)
+#define H5FL_ARR_EXTERN(t) extern H5_DLL H5FL_ARR_DEFINE_COMMON(t,m)
+#define H5FL_ARR_DEFINE_STATIC(t,m) static H5FL_ARR_DEFINE_COMMON(t,m) = 0
+#define H5FL_BARR_DEFINE_STATIC(t,m) static H5FL_ARR_DEFINE_COMMON(t,m) = sizeof(b)
+#define H5FL_ARR_MALLOC(t,elem) H5MM_malloc(H5FL_ARR_NAME(t) + ((elem)*sizeof(t)))
+#define H5FL_ARR_CALLOC(t,elem) H5MM_calloc(H5FL_ARR_NAME(t) + ((elem)*sizeof(t)))
#define H5FL_ARR_FREE(t,obj) H5MM_xfree(obj)
-#define H5FL_ARR_REALLOC(t,obj,new_elem) H5MM_realloc(obj,(new_elem)*sizeof(t))
+#define H5FL_ARR_REALLOC(t,obj,new_elem) H5MM_realloc(obj,H5FL_ARR_NAME(t) + ((new_elem)*sizeof(t)))
#endif /* H5_NO_ARR_FREE_LISTS */
/* Data structure for free list of sequence blocks */
diff --git a/src/H5SL.c b/src/H5SL.c
index 85d7080..3748644 100644
--- a/src/H5SL.c
+++ b/src/H5SL.c
@@ -52,7 +52,6 @@
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free Lists */
-#include "H5MMprivate.h" /* Memory management */
#include "H5SLprivate.h" /* Skip list routines */
/* Local Macros */
@@ -75,7 +74,7 @@
else \
X->forward[0]->backward=X->backward; \
tmp=X->item; \
- H5MM_xfree(X); \
+ H5FL_ARR_FREE(H5SL_node_ptr_t,X); \
while(SLIST->curr_level>0 && SLIST->header->forward[SLIST->curr_level]==NULL) \
SLIST->curr_level--; \
SLIST->nobjs--; \
@@ -182,6 +181,10 @@ static herr_t H5SL_close_common(H5SL_t *slist, H5SL_operator_t op, void *op_data
/* Declare a free list to manage the H5SL_t struct */
H5FL_DEFINE_STATIC(H5SL_t);
+/* Declare a "base + array" list to manage the H5SL_node_t struct */
+typedef H5SL_node_t *H5SL_node_ptr_t;
+H5FL_BARR_DEFINE_STATIC(H5SL_node_t,H5SL_node_ptr_t,H5SL_LEVEL_MAX);
+
/*--------------------------------------------------------------------------
NAME
@@ -289,7 +292,7 @@ H5SL_new_node(size_t lvl, void *item, const void *key)
FUNC_ENTER_NOAPI_NOINIT(H5SL_new_node);
/* Allocate the node */
- if((ret_value=H5MM_malloc(sizeof(H5SL_node_t)+(sizeof(H5SL_node_t *)*(lvl+1))))==NULL)
+ if((ret_value=H5FL_ARR_MALLOC(H5SL_node_ptr_t,(lvl+1)))==NULL)
HGOTO_ERROR(H5E_SLIST,H5E_NOSPACE,NULL,"memory allocation failed");
/* Initialize node */
@@ -465,7 +468,7 @@ H5SL_release_common(H5SL_t *slist, H5SL_operator_t op, void *op_data)
if(op!=NULL)
(void)(op)(node->item,(void *)node->key,op_data);
- H5MM_xfree(node);
+ H5FL_ARR_FREE(H5SL_node_ptr_t,node);
node=next_node;
} /* end while */
@@ -522,7 +525,7 @@ H5SL_close_common(H5SL_t *slist, H5SL_operator_t op, void *op_data)
(void)H5SL_release_common(slist,op,op_data); /* always succeeds */
/* Release header node */
- H5MM_xfree(slist->header);
+ H5FL_ARR_FREE(H5SL_node_ptr_t,slist->header);
/* Free skip list object */
H5FL_FREE(H5SL_t,slist);