diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 1999-08-19 18:50:22 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 1999-08-19 18:50:22 (GMT) |
commit | 2468fb8bafb28aaaf05ece5bf65e98f9ec7d5e3e (patch) | |
tree | 841c49cfd7f8f5d7ed28453b478b14aeb9c3010b /src/H5TB.c | |
parent | fc9d502859d8e4c2767f4bc83b64ccbc40499278 (diff) | |
download | hdf5-2468fb8bafb28aaaf05ece5bf65e98f9ec7d5e3e.zip hdf5-2468fb8bafb28aaaf05ece5bf65e98f9ec7d5e3e.tar.gz hdf5-2468fb8bafb28aaaf05ece5bf65e98f9ec7d5e3e.tar.bz2 |
[svn-r1576] Added H5Dvlen_get_buf_size function.
Diffstat (limited to 'src/H5TB.c')
-rw-r--r-- | src/H5TB.c | 101 |
1 files changed, 52 insertions, 49 deletions
@@ -377,59 +377,62 @@ H5TB_resize_buf(hid_t tbuf_id, hsize_t size, void **ptr) HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a temp. buffer"); } - /* Save old pointer for later */ - old_ptr=tbuf->buf; - - /* Try to resize buffer to new size */ - if((tbuf->buf = H5MM_realloc(tbuf->buf, size))==NULL) { - tbuf->buf=old_ptr; /* restore pointer if no memory available */ - HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, - "unable to allocate space for temporary buffer"); - } + /* Check if we actually need to re-size the buffer */ + if(size > tbuf->size) { + /* Save old pointer for later */ + old_ptr=tbuf->buf; + + /* Try to resize buffer to new size */ + if((tbuf->buf = H5MM_realloc(tbuf->buf, size))==NULL) { + tbuf->buf=old_ptr; /* restore pointer if no memory available */ + HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "unable to allocate space for temporary buffer"); + } - /* Change the size of the buffer */ - tbuf->size=size; + /* Change the size of the buffer */ + tbuf->size=size; + + /* + * Check if we need to move the buffer in the sorted list + */ + + /* Check if this is not the last node and it needs to move */ + if(tbuf->next!=NULL && tbuf->next->size < tbuf->size) { + /* Remove this node from the list */ + if(tbuf->prev==NULL) { /* remove from head of list */ + H5TB_list_head=tbuf->next; + tbuf->next->prev=NULL; + } else { /* remove from middle of list */ + tbuf->prev->next=tbuf->next; + tbuf->next->prev=tbuf->prev; + } /* end if */ - /* - * Check if we need to move the buffer in the sorted list - */ + /* Find correct position in list */ + curr=H5TB_list_head; + while(curr!=NULL) { + if(!curr->inuse && size<curr->size) + break; + curr=curr->next; + } /* end while */ - /* Check if this is not the last node and it need's to move */ - if(tbuf->next!=NULL && tbuf->next->size < tbuf->size) { - /* Remove this node from the list */ - if(tbuf->prev==NULL) { /* remove from head of list */ - H5TB_list_head=tbuf->next; - tbuf->next->prev=NULL; - } else { /* remove from middle of list */ - tbuf->prev->next=tbuf->next; - tbuf->next->prev=tbuf->prev; + /* Insert into correct position in list */ + if(curr!=NULL) { + /* + * Can't be adding to the beginning of list, so this is in the + * middle somewhere. + */ + curr->prev->next=tbuf; + tbuf->prev=curr->prev; + curr->prev=tbuf; + tbuf->next=curr; + } else { /* append to end of list */ + H5TB_list_tail->next=tbuf; + tbuf->prev=H5TB_list_tail; + tbuf->next=NULL; + H5TB_list_tail=tbuf; + } /* end else */ } /* end if */ - - /* Find correct position in list */ - curr=H5TB_list_head; - while(curr!=NULL) { - if(!curr->inuse && size<curr->size) - break; - curr=curr->next; - } /* end while */ - - /* Insert into correct position in list */ - if(curr!=NULL) { - /* - * Can't be adding to the beginning of list, so this is in the - * middle somewhere. - */ - curr->prev->next=tbuf; - tbuf->prev=curr->prev; - curr->prev=tbuf; - tbuf->next=curr; - } else { /* append to end of list */ - H5TB_list_tail->next=tbuf; - tbuf->prev=H5TB_list_tail; - tbuf->next=NULL; - H5TB_list_tail=tbuf; - } /* end else */ - } /* end if */ + } /* end if */ /* Assign the pointer to the buffer, if requested */ if(ptr!=NULL) |