base: Add Allocator_avl::size_at function

This function provides a way to request the size of an previously
allocated block. It is useful to to ease the implementation of realloc
functionality based on Allocator_avl.
This commit is contained in:
Norman Feske 2013-08-26 17:24:55 +02:00 committed by Christian Helmuth
parent 16bc2bc840
commit db2fe17269
2 changed files with 14 additions and 0 deletions

View File

@ -231,6 +231,11 @@ namespace Genode {
void free(void *addr, size_t) { free(addr); } void free(void *addr, size_t) { free(addr); }
/**
* Return size of block at specified address
*/
size_t size_at(void const *addr) const;
/** /**
* Return the memory overhead per Block * Return the memory overhead per Block
* *

View File

@ -339,6 +339,15 @@ void Allocator_avl_base::free(void *addr)
} }
size_t Allocator_avl_base::size_at(void const *addr) const
{
/* lookup corresponding block */
Block *b = _find_by_address(reinterpret_cast<addr_t>(addr));
return (b && b->used()) ? b->size() : 0;
}
bool Allocator_avl_base::any_block_addr(addr_t *out_addr) bool Allocator_avl_base::any_block_addr(addr_t *out_addr)
{ {
Block *b = _addr_tree.first(); Block *b = _addr_tree.first();