@@ -650,14 +650,15 @@ void *umm_realloc( void *ptr, size_t size ) {
650
650
* out the best strategy for the new allocation. The following strategy is
651
651
* focused on defragging the heap:
652
652
*
653
- * 1. If the new block is the same size or smaller than the current block do
654
- * nothing.
655
- * 2. If the prev is free and adding it to the current and next block
656
- * gives us enough memory, proceed, note that next block may not be
657
- * available.
653
+ * 1. If the prev is free and adding it to the current, or current and next
654
+ * block, gives us enough memory, proceed. Note, that next block may not
655
+ * be available.
658
656
* a. Remove the previous block from the free list, assimilate it.
659
- * b. If new block gives enough memory, copy to the new block.
657
+ * b. If this new block gives enough memory, copy to the new block.
658
+ * Note, this includes the case of same size or smaller block.
660
659
* c. Else assimilate the next block, copy to the new block.
660
+ * 2. If the new block is the same size or smaller than the current block do
661
+ * nothing.
661
662
* 3. If the next block is free and adding it to the current block gives us
662
663
* enough memory, assimilate the next block.
663
664
* 4. Otherwise try to allocate an entirely new block of memory. If the
@@ -668,10 +669,7 @@ void *umm_realloc( void *ptr, size_t size ) {
668
669
* was not exact, then split the memory block so that we use only the
669
670
* requested number of blocks and add what's left to the free list.
670
671
*/
671
- if (blockSize >= blocks ) { // 1
672
- DBGLOG_DEBUG ( "realloc the same or smaller size block - %d, do nothing\n" , blocks );
673
- /* This space intentionally left blank */
674
- } else if (prevBlockSize && (prevBlockSize + blockSize + nextBlockSize ) >= blocks ) { // 2
672
+ if (prevBlockSize && (prevBlockSize + blockSize + nextBlockSize ) >= blocks ) { // 1
675
673
umm_disconnect_from_free_list ( UMM_PBLOCK (c ) );
676
674
c = umm_assimilate_down (c , 0 );
677
675
STATS__FREE_BLOCKS_UPDATE ( - prevBlockSize );
@@ -697,6 +695,9 @@ void *umm_realloc( void *ptr, size_t size ) {
697
695
memmove ( (void * )& UMM_DATA (c ), ptr , curSize );
698
696
ptr = (void * )& UMM_DATA (c );
699
697
UMM_CRITICAL_RESUME (id_realloc );
698
+ } else if (blockSize >= blocks ) { // 2
699
+ DBGLOG_DEBUG ( "realloc the same or smaller size block - %d, do nothing\n" , blocks );
700
+ /* This space intentionally left blank */
700
701
} else if ((blockSize + nextBlockSize ) >= blocks ) { // 3
701
702
DBGLOG_DEBUG ( "realloc using next block - %d\n" , blocks );
702
703
umm_assimilate_up ( c );
0 commit comments