summaryrefslogtreecommitdiffstats
path: root/src/H5Tconv.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-06-29 03:12:45 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-06-29 03:12:45 (GMT)
commitcad9846d77ea4926bb0f13cf5151c1a7ac05ec87 (patch)
treec88b30412b25b6fc5df9534a6ff2cf1742393a36 /src/H5Tconv.c
parent58467956ba56fc52dd03e3540f14b062f9a6c5bb (diff)
downloadhdf5-cad9846d77ea4926bb0f13cf5151c1a7ac05ec87.zip
hdf5-cad9846d77ea4926bb0f13cf5151c1a7ac05ec87.tar.gz
hdf5-cad9846d77ea4926bb0f13cf5151c1a7ac05ec87.tar.bz2
[svn-r13926] Description:
Add small interface to "wrap" a static buffer (usually on the stack), but still allow for buffers larger than the static buffer to be allocated. This can eliminate _many_ short-lived buffer allocations in situations where the buffer is a predictable size (or at least a "very likely" size). Also, some minor code cleanups, particularly in the SOHM caching code. Tested on: Mac OS X/32 10.4.10 (amazon)
Diffstat (limited to 'src/H5Tconv.c')
-rw-r--r--src/H5Tconv.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/H5Tconv.c b/src/H5Tconv.c
index b5cc696..e0d878a 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -3163,8 +3163,7 @@ H5T_conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
int direction; /*direction of traversal */
size_t elmtno; /*element number counter */
unsigned u; /* local index variable */
- void *bkg_buf=NULL; /*temporary background buffer */
- size_t bkg_buf_size=0; /*size of background buffer in bytes */
+ void *bkg_buf = NULL; /*temporary background buffer */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5T_conv_array, FAIL)
@@ -3239,10 +3238,12 @@ H5T_conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
/* Check if we need a background buffer for this conversion */
if(tpath->cdata.need_bkg) {
+ size_t bkg_buf_size; /*size of background buffer in bytes */
+
/* Allocate background buffer */
bkg_buf_size = src->shared->u.array.nelem * MAX(src->shared->size, dst->shared->size);
- if((bkg_buf = H5FL_BLK_CALLOC(array_seq, bkg_buf_size)) == NULL)
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
+ if(NULL == (bkg_buf = H5FL_BLK_CALLOC(array_seq, bkg_buf_size)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
} /* end if */
/* Perform the actual conversion */
@@ -3259,10 +3260,6 @@ H5T_conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
dp += dst_delta;
} /* end for */
- /* Release the background buffer, if we have one */
- if(bkg_buf != NULL)
- H5FL_BLK_FREE(array_seq, bkg_buf);
-
/* Release the temporary datatype IDs used */
if(tsrc_id >= 0)
H5I_dec_ref(tsrc_id);
@@ -3275,6 +3272,10 @@ H5T_conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
} /* end switch */
done:
+ /* Release the background buffer, if we have one */
+ if(bkg_buf)
+ H5FL_BLK_FREE(array_seq, bkg_buf);
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_conv_array() */