mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Merged changes
This commit is contained in:
parent
464a26733b
commit
e35490bc3f
@ -216,6 +216,58 @@ namespace etl
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
///
|
||||
//*************************************************************************
|
||||
void release_block(char* ptr)
|
||||
{
|
||||
header* block;
|
||||
header* p;
|
||||
|
||||
// acquire pointer to block header
|
||||
block = reinterpret_cast<header*>(ptr) - 1;
|
||||
|
||||
// Find the correct place to place the block in (the free list is sorted by
|
||||
// address, increasing order)
|
||||
//
|
||||
for (p = head; !(block > p && block < p->next); p = p->next)
|
||||
{
|
||||
// Since the free list is circular, there is one link where a
|
||||
// higher-addressed block points to a lower-addressed block.
|
||||
// This condition checks if the block should be actually
|
||||
// inserted between them
|
||||
//
|
||||
if (p >= p->next && (block > p || block < p->next))
|
||||
break;
|
||||
}
|
||||
|
||||
// Try to combine with the higher neighbor
|
||||
//
|
||||
if (block + block->size() == p->next)
|
||||
{
|
||||
block->size += p->next->size;
|
||||
block->next = p->next->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
block->next = p->next;
|
||||
}
|
||||
|
||||
// Try to combine with the lower neighbor
|
||||
//
|
||||
if (p + p->size == block)
|
||||
{
|
||||
p->size += block->size;
|
||||
p->next = block->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->next = block;
|
||||
}
|
||||
|
||||
free_p = p;
|
||||
}
|
||||
|
||||
char* pbuffer;
|
||||
size_t buffer_size;
|
||||
header* head;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user