From 9ec791db9aeca7b092859f018f6b1b415a8b4ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Wed, 6 Mar 2013 13:01:26 +0100 Subject: [PATCH] base: add method to withdraw memory w/o allocating The given number of bytes is consumed but not actually allocated. This feature may be used for accounting and use memory within core which is in fact provided by a session client. Fixes #792. --- base/include/base/allocator_guard.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/base/include/base/allocator_guard.h b/base/include/base/allocator_guard.h index 579dad351..a0fcbd341 100644 --- a/base/include/base/allocator_guard.h +++ b/base/include/base/allocator_guard.h @@ -43,6 +43,17 @@ namespace Genode { void upgrade(size_t additional_amount) { _amount += additional_amount; } + /** + * Consume bytes without actually allocating them + */ + bool withdraw(size_t size) + { + if ((_amount - _consumed) < size) + return false; + + _consumed += size; + return true; + } /************************* ** Allocator interface **