summaryrefslogtreecommitdiffstats
path: root/src/H5H.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1997-08-09 16:45:59 (GMT)
committerRobb Matzke <matzke@llnl.gov>1997-08-09 16:45:59 (GMT)
commita260c7849c1ca59bd32cde9d12380e89afd70770 (patch)
treea4d791e5df2d17b3fd6988ca84e363560b1c87cf /src/H5H.c
parent0d050fcd579bf1db6db2d8a1d3fec617114bfd1f (diff)
downloadhdf5-a260c7849c1ca59bd32cde9d12380e89afd70770.zip
hdf5-a260c7849c1ca59bd32cde9d12380e89afd70770.tar.gz
hdf5-a260c7849c1ca59bd32cde9d12380e89afd70770.tar.bz2
[svn-r17] ./src/H5AC.c
Renamed H5AC_find() to H5AC_find_f() which is invoked from the H5AC_find() macro. Changed HASH() to H5AC_HASH(). ./src/H5ACprivate.h Increased the number of cache slots from 1033 to 10330 to see how it affects performance. This should probably be changeable on a per-file basis. ./src/H5B.c Fixed some bugs now that symbol tables are actually using the stuff. Improved debugging a little. Fixed uninitialized memory appearing in the file. ./src/H5D.c Changed a FUNC_ENTER() argument from H5Dset_info to H5Dwrite. ./src/H5F.c Plugged a memory leak in H5F_dest(). ./src/H5G.c ./src/H5Gprivate.h Many of these functions take a symbol table entry which describes the symbol table rather than just the symbol table address. Moved some functions to make room for the ones that understand directory names: H5G_new() -> H5G_stab_new() H5G_find() -> H5G_stab_find() H5G_modify() -> H5G_stab_modify() H5G_insert() -> H5G_stab_insert() H5G_list() -> H5G_stab_list() ./src/H5Gnode.c Added more assertions. Zero new memory so junk doesn't appear in the data file. This is a problem when one tries to declassify a classified data file. H5G_node_debug() can take an extra argument which is the address of the heap for the symbol table. If supplied, the symbol names are printed along with the heap offsets. ./src/H5H.c ./src/H5Hprivate.h Fixed a bug with the free blocks by forcing things to align on even boundaries. It's still possible to lose heap memory if the hole is smaller than the free list header. The alternative is to align heap objects on 12 or 20 byte boundaries, but this tends to waste to much space. Zero new memory like with H5Gnode.c. Fixed a "mispeling" of NDEBUG. ./src/H5Ocont.c ./src/H5Onull.c Added the pablo mask defn. ./src/H5Ostab.c Added the pablo mask defn. Fixed a read from uninitialized memory. ./src/H5Oprivate.h Tuned some parameters to see how they affect performance. ./src/debug.c An optional third argument can be supplied which is the address of a heap to use to display names in a symbol table. ./src/hdf5pabl.h Changed `int' to `intn'.
Diffstat (limited to 'src/H5H.c')
-rw-r--r--src/H5H.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/H5H.c b/src/H5H.c
index 8a58f2a..2a92dee 100644
--- a/src/H5H.c
+++ b/src/H5H.c
@@ -132,7 +132,7 @@ H5H_new (hdf5_file_t *f, H5H_type_t heap_type, size_t size_hint)
heap->addr = addr + H5H_SIZEOF_HDR(f);
heap->disk_alloc = size_hint;
heap->mem_alloc = size_hint;
- heap->chunk = H5MM_xmalloc (H5H_SIZEOF_HDR(f) + size_hint);
+ heap->chunk = H5MM_xcalloc (1, H5H_SIZEOF_HDR(f)+size_hint);
/* free list */
if (size_hint) {
@@ -179,7 +179,7 @@ H5H_load (hdf5_file_t *f, haddr_t addr, const void *udata)
uint8 hdr[20], *p;
H5H_t *heap=NULL;
H5H_free_t *fl=NULL, *tail=NULL;
- haddr_t free_block;
+ haddr_t free_block=H5H_FREE_NULL;
FUNC_ENTER (H5H_load, NULL, NULL);
@@ -211,7 +211,7 @@ H5H_load (hdf5_file_t *f, haddr_t addr, const void *udata)
/* data */
H5F_decode_offset (f, p, heap->addr);
- heap->chunk = H5MM_xmalloc (H5H_SIZEOF_HDR(f) + heap->mem_alloc);
+ heap->chunk = H5MM_xcalloc (1, H5H_SIZEOF_HDR(f) + heap->mem_alloc);
if (heap->disk_alloc &&
H5F_block_read (f, heap->addr, heap->disk_alloc,
heap->chunk + H5H_SIZEOF_HDR(f))<0) {
@@ -517,12 +517,12 @@ H5H_remove_free (H5H_t *heap, H5H_free_t *fl)
*-------------------------------------------------------------------------
*/
off_t
-H5H_insert (hdf5_file_t *f, haddr_t addr, size_t size, const void *buf)
+H5H_insert (hdf5_file_t *f, haddr_t addr, size_t buf_size, const void *buf)
{
H5H_t *heap=NULL;
H5H_free_t *fl=NULL, *max_fl=NULL;
off_t offset = -1;
- size_t need_more;
+ size_t need, old_size, need_more;
#ifndef NDEBUG
static nmessages = 0;
#endif
@@ -533,9 +533,13 @@ H5H_insert (hdf5_file_t *f, haddr_t addr, size_t size, const void *buf)
assert (f);
if (H5H_GLOBAL==addr) addr = f->smallobj_off;
assert (addr>0);
- assert (size>0);
+ assert (buf_size>0);
assert (buf);
+ /* allocate aligned file memory */
+ need = buf_size;
+ H5H_ALIGN (need);
+
if (NULL==(heap=H5AC_find (f, H5AC_HEAP, addr, NULL))) {
HRETURN_ERROR (H5E_HEAP, H5E_CANTLOAD, FAIL);
}
@@ -546,12 +550,12 @@ H5H_insert (hdf5_file_t *f, haddr_t addr, size_t size, const void *buf)
* leave zero or at least H5G_SIZEOF_FREE bytes left over.
*/
for (fl=heap->freelist; fl; fl=fl->next) {
- if (fl->size>size && fl->size-size>=H5H_SIZEOF_FREE(f)) {
+ if (fl->size>need && fl->size-need>=H5H_SIZEOF_FREE(f)) {
offset = fl->offset;
- fl->offset += size;
- fl->size -= size;
+ fl->offset += need;
+ fl->size -= need;
break;
- } else if (fl->size==size) {
+ } else if (fl->size==need) {
offset = fl->offset;
H5H_remove_free (heap, fl);
break;
@@ -570,15 +574,15 @@ H5H_insert (hdf5_file_t *f, haddr_t addr, size_t size, const void *buf)
if (offset<0) {
need_more = MAX (2*heap->mem_alloc, H5H_SIZEOF_FREE(f));
- need_more = MAX (need_more, size);
+ need_more = MAX (need_more, need);
if (max_fl && max_fl->offset+max_fl->size==heap->mem_alloc) {
/*
* Increase the size of the maximum free block.
*/
offset = max_fl->offset;
- max_fl->offset += size;
- max_fl->size += need_more - size;
+ max_fl->offset += need;
+ max_fl->size += need_more - need;
if (max_fl->size < H5H_SIZEOF_FREE(f)) {
#ifndef NDEBUG
@@ -600,18 +604,18 @@ H5H_insert (hdf5_file_t *f, haddr_t addr, size_t size, const void *buf)
* take some space out of it right away.
*/
offset = heap->mem_alloc;
- if (need_more-size >= H5H_SIZEOF_FREE(f)) {
+ if (need_more-need >= H5H_SIZEOF_FREE(f)) {
fl = H5MM_xmalloc (sizeof(H5H_free_t));
- fl->offset = heap->mem_alloc + size;
- fl->size = need_more - size;
+ fl->offset = heap->mem_alloc + need;
+ fl->size = need_more - need;
fl->prev = NULL;
fl->next = heap->freelist;
if (heap->freelist) heap->freelist->prev = fl;
heap->freelist = fl;
#ifndef NDEBUG
- } else if (need_more>size) {
+ } else if (need_more>need) {
fprintf (stderr, "H5H_insert: lost %d bytes at line %d\n",
- need_more-size, __LINE__);
+ need_more-need, __LINE__);
if (0==nmessages++) {
fprintf (stderr, "Messages from H5H_insert() will go away "
"when assertions are turned off.\n");
@@ -629,15 +633,19 @@ H5H_insert (hdf5_file_t *f, haddr_t addr, size_t size, const void *buf)
"when assertions are turned off.\n");
}
#endif
+ old_size = heap->mem_alloc;
heap->mem_alloc += need_more;
heap->chunk = H5MM_xrealloc (heap->chunk,
H5H_SIZEOF_HDR(f)+heap->mem_alloc);
+
+ /* clear new section so junk doesn't appear in the file */
+ memset (heap->chunk+H5H_SIZEOF_HDR(f)+old_size, 0, need_more);
}
/*
* Copy the data into the heap
*/
- HDmemcpy (heap->chunk + H5H_SIZEOF_HDR(f) + offset, buf, size);
+ HDmemcpy (heap->chunk + H5H_SIZEOF_HDR(f) + offset, buf, buf_size);
FUNC_LEAVE (offset);
}
@@ -796,7 +804,7 @@ H5H_remove (hdf5_file_t *f, haddr_t addr, off_t offset, size_t size)
* lost.
*/
if (size < H5H_SIZEOF_FREE(f)) {
-#ifndef NDEUBG
+#ifndef NDEBUG
fprintf (stderr, "H5H_remove: lost %d bytes\n", size);
if (0==nmessages++) {
fprintf (stderr, "Messages from H5H_remove() will go away "