From 672d28883c738cd325f1f3020ffad787be14dbdb Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Mon, 22 Nov 2004 14:53:24 -0500 Subject: [svn-r9560] Purpose: Code optimization Description: Switch a few more malloc/free pairs over to using internal free list code, to avoid abusing system memory allocator as badly. Platforms tested: FreeBSD 4.10 (sleipnir) w/parallel Solaris 2.7 (arabica) Too minor to require h5committest --- src/H5A.c | 25 ++++++++++++++----------- src/H5Gnode.c | 12 ++++++++---- src/H5Oattr.c | 5 ++++- src/H5Ostab.c | 16 +++++++--------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index cef2767..af55838 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -57,6 +57,9 @@ static herr_t H5A_find_idx_by_name(const void *mesg, unsigned idx, void *op_data /* Declare the free lists for H5A_t's */ H5FL_DEFINE(H5A_t); +/* Declare a free list to manage blocks of type conversion data */ +H5FL_BLK_DEFINE(attr_buf); + /*-------------------------------------------------------------------------- NAME @@ -688,7 +691,7 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id) /* Get the maximum buffer size needed and allocate it */ buf_size=nelmts*MAX(src_type_size,dst_type_size); - if (NULL==(tconv_buf = H5MM_malloc (buf_size)) || NULL==(bkg_buf = H5MM_calloc(buf_size))) + if (NULL==(tconv_buf = H5FL_BLK_MALLOC (attr_buf, buf_size)) || NULL==(bkg_buf = H5FL_BLK_CALLOC(attr_buf, buf_size))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy the user's data into the buffer for conversion */ @@ -700,7 +703,7 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id) /* Free the previous attribute data buffer, if there is one */ if(attr->data) - H5MM_xfree(attr->data); + H5FL_BLK_FREE(attr_buf, attr->data); /* Set the pointer to the attribute data to the converted information */ attr->data=tconv_buf; @@ -711,7 +714,7 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id) /* Allocate the attribute buffer, if there isn't one */ if(attr->data==NULL) - if (NULL==(attr->data = H5MM_malloc (dst_type_size*nelmts))) + if (NULL==(attr->data = H5FL_BLK_MALLOC(attr_buf, dst_type_size*nelmts))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy the attribute data into the user's buffer */ @@ -737,7 +740,7 @@ done: if (dst_id >= 0) (void)H5I_dec_ref(dst_id); if (bkg_buf) - H5MM_xfree(bkg_buf); + H5FL_BLK_FREE(attr_buf, bkg_buf); FUNC_LEAVE_NOAPI(ret_value) } /* H5A_write() */ @@ -854,7 +857,7 @@ H5A_read(const H5A_t *attr, const H5T_t *mem_type, void *buf, hid_t dxpl_id) /* Get the maximum buffer size needed and allocate it */ buf_size=nelmts*MAX(src_type_size,dst_type_size); - if (NULL==(tconv_buf = H5MM_malloc (buf_size)) || NULL==(bkg_buf = H5MM_calloc(buf_size))) + if (NULL==(tconv_buf = H5FL_BLK_MALLOC(attr_buf, buf_size)) || NULL==(bkg_buf = H5FL_BLK_CALLOC(attr_buf, buf_size))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Copy the attribute data into the buffer for conversion */ @@ -884,9 +887,9 @@ done: if (dst_id >= 0) (void)H5I_dec_ref(dst_id); if (tconv_buf) - H5MM_xfree(tconv_buf); + H5FL_BLK_FREE(attr_buf, tconv_buf); if (bkg_buf) - H5MM_xfree(bkg_buf); + H5FL_BLK_FREE(attr_buf, bkg_buf); FUNC_LEAVE_NOAPI(ret_value) } /* H5A_read() */ @@ -1558,7 +1561,7 @@ H5A_copy(H5A_t *_new_attr, const H5A_t *old_attr, unsigned update_flags) } /* end if */ if(old_attr->data) { if(!(update_flags&H5O_UPDATE_DATA_ONLY) || new_attr->data==NULL) { - if (NULL==(new_attr->data=H5MM_malloc(old_attr->data_size))) + if (NULL==(new_attr->data=H5FL_BLK_MALLOC(attr_buf,old_attr->data_size))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") } /* end if */ HDmemcpy(new_attr->data,old_attr->data,old_attr->data_size); @@ -1611,7 +1614,7 @@ H5A_free(H5A_t *attr) if(H5S_close(attr->ds)<0) HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release dataspace info") if(attr->data) - H5MM_xfree(attr->data); + H5FL_BLK_FREE(attr_buf, attr->data); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1643,7 +1646,7 @@ H5A_close(H5A_t *attr) /* Check if the attribute has any data yet, if not, fill with zeroes */ if(attr->ent_opened && !attr->initialized) { - uint8_t *tmp_buf=H5MM_calloc(attr->data_size); + uint8_t *tmp_buf=H5FL_BLK_CALLOC(attr_buf, attr->data_size); if (NULL == tmp_buf) HGOTO_ERROR(H5E_ATTR, H5E_NOSPACE, FAIL, "memory allocation failed for attribute fill-value") @@ -1652,7 +1655,7 @@ H5A_close(H5A_t *attr) HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "unable to write attribute") /* Free temporary buffer */ - H5MM_xfree(tmp_buf); + H5FL_BLK_FREE(attr_buf, tmp_buf); } /* end if */ /* Free dynamicly allocated items */ diff --git a/src/H5Gnode.c b/src/H5Gnode.c index 48d9879..9fdcc5c 100644 --- a/src/H5Gnode.c +++ b/src/H5Gnode.c @@ -30,6 +30,10 @@ #define H5G_PACKAGE /*suppress error message about including H5Gpkg.h */ #define H5F_PACKAGE /*suppress error about including H5Fpkg */ +/* Pablo information */ +/* (Put before include files to avoid problems with inline functions) */ +#define PABLO_MASK H5G_node_mask + /* Packages needed by this file... */ #include "H5private.h" /* Generic Functions */ #include "H5ACprivate.h" /* Metadata cache */ @@ -59,8 +63,6 @@ typedef struct H5G_node_key_t { #define H5G_NODE_VERS 1 /*symbol table node version number */ #define H5G_NODE_SIZEOF_HDR(F) (H5G_NODE_SIZEOF_MAGIC + 4) -#define PABLO_MASK H5G_node_mask - /* PRIVATE PROTOTYPES */ static herr_t H5G_node_serialize(H5F_t *f, H5G_node_t *sym, size_t size, uint8_t *buf); static size_t H5G_node_size(H5F_t *f); @@ -1488,7 +1490,7 @@ H5G_node_iterate (H5F_t *f, hid_t dxpl_id, void UNUSED *_lt_key, haddr_t addr, if (NULL == (sn = H5AC_protect(f, dxpl_id, H5AC_SNODE, addr, NULL, NULL, H5AC_READ))) HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, H5B_ITER_ERROR, "unable to load symbol table node"); nsyms = sn->nsyms; - if (NULL==(name_off = H5MM_malloc (nsyms*sizeof(name_off[0])))) + if (NULL==(name_off = H5FL_SEQ_MALLOC(size_t, nsyms))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, H5B_ITER_ERROR, "memory allocation failed"); for (i=0; ientry[i].name_off; @@ -1545,7 +1547,9 @@ done: if (sn && H5AC_unprotect(f, dxpl_id, H5AC_SNODE, addr, sn, FALSE) != SUCCEED) HDONE_ERROR(H5E_SYM, H5E_PROTECT, H5B_ITER_ERROR, "unable to release object header"); - name_off = H5MM_xfree (name_off); + if(name_off) + H5FL_SEQ_FREE(size_t,name_off); + FUNC_LEAVE_NOAPI(ret_value); } diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 7e4314e..c4ae58a 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -74,6 +74,9 @@ const H5O_class_t H5O_ATTR[1] = {{ /* Declare extern the free list for H5A_t's */ H5FL_EXTERN(H5A_t); +/* Declare extern the free list for attribute data buffers */ +H5FL_BLK_EXTERN(attr_buf); + /* Declare external the free list for H5S_t's */ H5FL_EXTERN(H5S_t); @@ -206,7 +209,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p, H5O_shared_t UNUSED * /* Go get the data */ if(attr->data_size) { - if (NULL==(attr->data = H5MM_malloc(attr->data_size))) + if (NULL==(attr->data = H5FL_BLK_MALLOC(attr_buf, attr->data_size))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); HDmemcpy(attr->data,p,attr->data_size); } diff --git a/src/H5Ostab.c b/src/H5Ostab.c index 3b8dec6..cd34fcb 100644 --- a/src/H5Ostab.c +++ b/src/H5Ostab.c @@ -179,8 +179,7 @@ H5O_stab_encode(H5F_t *f, uint8_t *p, const void *_mesg) void * H5O_stab_fast(const H5G_cache_t *cache, const H5O_class_t *type, void *_mesg) { - H5O_stab_t *stab = NULL; - void *ret_value; /* Return value */ + H5O_stab_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_stab_fast); @@ -190,16 +189,15 @@ 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 = H5FL_CALLOC(H5O_stab_t))) { + ret_value = (H5O_stab_t *) _mesg; + } else if (NULL==(ret_value = H5FL_MALLOC(H5O_stab_t))) { HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); } - stab->btree_addr = cache->stab.btree_addr; - stab->heap_addr = cache->stab.heap_addr; + ret_value->btree_addr = cache->stab.btree_addr; + ret_value->heap_addr = cache->stab.heap_addr; } - - /* Set return value */ - ret_value=stab; + else + ret_value=NULL; done: FUNC_LEAVE_NOAPI(ret_value); -- cgit v0.12