diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2007-06-29 03:12:45 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2007-06-29 03:12:45 (GMT) |
commit | cad9846d77ea4926bb0f13cf5151c1a7ac05ec87 (patch) | |
tree | c88b30412b25b6fc5df9534a6ff2cf1742393a36 /src/H5Sselect.c | |
parent | 58467956ba56fc52dd03e3540f14b062f9a6c5bb (diff) | |
download | hdf5-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/H5Sselect.c')
-rw-r--r-- | src/H5Sselect.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 666c8da..844317b 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -29,6 +29,7 @@ #include "H5Iprivate.h" /* IDs */ #include "H5Spkg.h" /* Dataspaces */ #include "H5Vprivate.h" /* Vector and array functions */ +#include "H5WBprivate.h" /* Wrapped Buffers */ /* Local functions */ #ifdef LATER @@ -37,8 +38,6 @@ static htri_t H5S_select_iter_has_next_block (const H5S_sel_iter_t *iter); static herr_t H5S_select_iter_next_block(H5S_sel_iter_t *iter); #endif /* LATER */ -/* Declare a free list to manage blocks of single datatype element data */ -H5FL_BLK_EXTERN(type_elem); /*-------------------------------------------------------------------------- @@ -1437,9 +1436,11 @@ herr_t H5S_select_fill(const void *_fill, size_t fill_size, const H5S_t *space, void *_buf) { H5S_sel_iter_t iter; /* Selection iteration info */ - hbool_t iter_init=0; /* Selection iteration info has been initialized */ + hbool_t iter_init = 0; /* Selection iteration info has been initialized */ + H5WB_t *elem_wb = NULL; /* Wrapped buffer for element data */ + uint8_t elem_buf[H5T_ELEM_BUF_SIZE]; /* Buffer for element data */ uint8_t *buf; /* Current location in buffer */ - const void *fill=_fill; /* Alias for fill-value buffer */ + const void *fill; /* Alias for fill-value buffer */ hssize_t nelmts; /* Number of elements in selection */ hsize_t off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ size_t len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ @@ -1457,10 +1458,17 @@ H5S_select_fill(const void *_fill, size_t fill_size, const H5S_t *space, void *_ assert(_buf); /* Check if we need a temporary fill value buffer */ - if(fill==NULL) { - if (NULL==(fill = H5FL_BLK_CALLOC(type_elem,fill_size))) - HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "fill value buffer allocation failed"); + if(_fill == NULL) { + /* Wrap the local buffer for elements */ + if(NULL == (elem_wb = H5WB_wrap(elem_buf, sizeof(elem_buf)))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't wrap buffer") + + /* Get a pointer to a buffer that's large enough for element */ + if(NULL == (fill = H5WB_actual_clear(elem_wb, fill_size))) + HGOTO_ERROR(H5E_DATASET, H5E_NOSPACE, FAIL, "can't get actual buffer") } /* end if */ + else + fill = _fill; /* Initialize iterator */ if (H5S_select_iter_init(&iter, space, fill_size)<0) @@ -1495,15 +1503,11 @@ H5S_select_fill(const void *_fill, size_t fill_size, const H5S_t *space, void *_ } /* end while */ done: - /* Release selection iterator */ - if(iter_init) { - if (H5S_SELECT_ITER_RELEASE(&iter)<0) - HDONE_ERROR (H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator"); - } /* end if */ - - /* Release fill value, if allocated */ - if(_fill==NULL && fill) - H5FL_BLK_FREE(type_elem, (void *)fill); /* casting away const OK - QAK */ + /* Release resouces */ + if(iter_init && H5S_SELECT_ITER_RELEASE(&iter) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator"); + if(elem_wb && H5WB_unwrap(elem_wb) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CLOSEERROR, FAIL, "can't close wrapped buffer") FUNC_LEAVE_NOAPI(ret_value); } /* H5S_select_fill() */ |