Implementing resize of heap blocks.

- adding mem_heap_try_resize_block routine that tries to resize
   block using free space that is located right after the resized block;
 - placing long-term blocks from start of heap space and short-term - from end
   of the space to increase probability of success of resizing just allocated
   long-term block;
 - adding mem_heap_try_resize_block invocation to 'test_heap' unit test.
This commit is contained in:
Ruben Ayrapetyan
2014-11-11 15:25:19 +03:00
parent 4875762cfc
commit bd60d1874b
3 changed files with 164 additions and 7 deletions
+24 -5
View File
@@ -22,17 +22,17 @@ extern long int time (long int *__timer);
extern int printf (__const char *__restrict __format, ...);
extern void *memset (void *__s, int __c, size_t __n);
// Heap size is 8K
const size_t test_heap_size = 8 * 1024;
// Heap size is 32K
const size_t test_heap_size = 32 * 1024;
// Iterations count
const uint32_t test_iters = 1024 * 1024;
const uint32_t test_iters = 64 * 1024;
// Subiterations count
const uint32_t test_sub_iters = 3;
const uint32_t test_sub_iters = 32;
// Threshold size of block to allocate
const uint32_t test_threshold_block_size = 2048;
const uint32_t test_threshold_block_size = 8192;
int
main( int __unused argc,
@@ -69,6 +69,25 @@ main( int __unused argc,
// mem_heap_print( true);
for ( uint32_t j = 0; j < subiters; j++ )
{
if ( ptrs[j] != NULL && (rand () % 2) == 0 )
{
for( size_t k = 0; k < sizes[j]; k++ )
{
JERRY_ASSERT( ptrs[j][k] == 0 );
}
size_t new_size = (unsigned int) rand() % ( test_threshold_block_size );
if (mem_heap_try_resize_block (ptrs[j], new_size))
{
sizes[j] = new_size;
memset (ptrs[j], 0, sizes[j]);
}
}
}
for ( uint32_t j = 0; j < subiters; j++ )
{
if ( ptrs[j] != NULL )