echo "generate test script"
./pool_test_gen 64 256 1024 16 true >pool_test.txt
-#echo "run test script, non-moveable"
-#./pool_test_run 64 256 <pool_test.txt
-
-#echo "run test script, last-fit, non-moveable"
-#./pool_test_run 64 256 true <pool_test.txt
-
-echo "run test script, moveable"
+echo "run test script"
./pool_test_run 64 256 false true <pool_test.txt
-
-#echo "run test script, last-fit, moveable"
-#./pool_test_run 64 256 true true <pool_test.txt
size_change += item->base - item->limit;
// calculate new spot if block is extended not moved
- gap = 0;
- if (mode & POOL_ALLOC_MODE_REALLOC_OFFSET) {
- va_start(ap, mode);
- gap = va_arg(ap, int);
- va_end(ap);
- }
- if ((mode & POOL_ALLOC_MODE_LAST_FIT) == 0) {
- new_base = item->base - gap;
- new_limit = new_base + size;
- }
- else {
- new_limit = item->limit - gap;
- new_base = new_limit - size;
- }
+ va_start(ap, mode);
+ new_base = item->base - va_arg(ap, int);
+ va_end(ap);
+ new_limit = new_base + size;
#ifndef TRY_BLOCKER
if (new_base >= item->prev->limit && new_limit <= item->next->base)
goto resize;
if (mode & POOL_ALLOC_MODE_REALLOC) {
// move ourself into found spot
// (throw away truncated parts before calling move routine)
-
- // in certain cases there can't be truncation, and we can also
- // guarantee the overlap direction, so prefer the move routine
- // for given direction (user doesn't need to provide other one)
- switch (mode) {
- case POOL_ALLOC_MODE_REALLOC:
- assert(head->move);
- head->move(item, new_base);
- break;
- case POOL_ALLOC_MODE_LAST_FIT | POOL_ALLOC_MODE_REALLOC:
- assert(head->move_up);
- head->move_up(item, new_limit);
- break;
- default:
- assert(head->move && head->move_up);
- if (base_offset < 0) {
- item->base -= base_offset;
- base_offset = 0;
- }
- if (limit_offset > 0) {
- item->limit -= limit_offset;
- limit_offset = 0;
- }
- base_offset += new_base;
- gap = base_offset - item->base; // amount to move by
- if (gap < 0)
- head->move(item, base_offset);
- else if (gap > 0)
- head->move_up(item, limit_offset + new_limit);
+ assert(head->move && head->move_up);
+ if (base_offset < 0) {
+ item->base -= base_offset;
+ base_offset = 0;
+ }
+ if (limit_offset > 0) {
+ item->limit -= limit_offset;
+ limit_offset = 0;
}
+ base_offset += new_base;
+ gap = base_offset - item->base; // amount to move by
+ if (gap < 0)
+ head->move(item, base_offset);
+ else if (gap > 0)
+ head->move_up(item, limit_offset + new_limit);
// remove from list
item->prev->next = item->next;
#define POOL_ALLOC_MODE_LAST_FIT 1
#define POOL_ALLOC_MODE_MOVEABLE 2
#define POOL_ALLOC_MODE_REALLOC 4
-#define POOL_ALLOC_MODE_REALLOC_OFFSET 8
void pool_init(
struct pool_head *head,
&head,
items + item,
size,
- mode | POOL_ALLOC_MODE_REALLOC
+ mode | POOL_ALLOC_MODE_REALLOC,
+ 0
);
printf(
"... %s\n",
&head,
items + item,
actual_old_size,
- mode | POOL_ALLOC_MODE_REALLOC
+ mode | POOL_ALLOC_MODE_REALLOC,
+ 0
)
);
}
mode ^ (
POOL_ALLOC_MODE_LAST_FIT |
POOL_ALLOC_MODE_REALLOC
- )
+ ),
+ size - actual_old_size
);
printf(
"... %s\n",
mode ^ (
POOL_ALLOC_MODE_LAST_FIT |
POOL_ALLOC_MODE_REALLOC
- )
+ ),
+ actual_old_size - size
)
);
}
&core_table,
&process->core_item,
calc.in_core_block - calc.block_base,
- POOL_ALLOC_MODE_MOVEABLE | POOL_ALLOC_MODE_REALLOC
+ POOL_ALLOC_MODE_MOVEABLE | POOL_ALLOC_MODE_REALLOC,
+ 0
)
);
#endif /* ! INDIRECT_CORE */
&core_table,
&process->core_item,
blocks,
- dir | (POOL_ALLOC_MODE_MOVEABLE | POOL_ALLOC_MODE_REALLOC)
+ dir | (POOL_ALLOC_MODE_MOVEABLE | POOL_ALLOC_MODE_REALLOC),
+ calc.block_base - block_base
)
);
#else /* INDIRECT_CORE */
&core_table,
&process->core_item,
blocks,
- dir | POOL_ALLOC_MODE_REALLOC
+ dir | POOL_ALLOC_MODE_REALLOC,
+ calc.block_base - block_base
)
) {
assert(blocks_change >= 0);
calc.in_core_block - calc.block_base + blocks,
process->flags & PROCESS_FLAGS_CORE_ITEM ?
POOL_ALLOC_MODE_MOVEABLE | POOL_ALLOC_MODE_REALLOC :
- POOL_ALLOC_MODE_MOVEABLE
+ POOL_ALLOC_MODE_MOVEABLE,
+ 0
)
);
process->flags |= PROCESS_FLAGS_CORE_ITEM;