base: introduce Allocator::try_alloc

This patch changes the 'Allocator' interface to the use of 'Attempt'
return values instead of using exceptions for propagating errors.

To largely uphold compatibility with components using the original
exception-based interface - in particluar use cases where an 'Allocator'
is passed to the 'new' operator - the traditional 'alloc' is still
supported. But it existes merely as a wrapper around the new
'try_alloc'.

Issue #4324
This commit is contained in:
Norman Feske
2021-11-10 12:01:32 +01:00
committed by Christian Helmuth
parent 9591e6caee
commit dc39a8db62
102 changed files with 2128 additions and 1710 deletions

View File

@ -51,9 +51,9 @@ Main::Main(Env &env) : heap(env.ram(), env.rm())
/* induce initial heap expansion to remove RM noise */
if (1) {
void *addr;
heap.alloc(0x100000, &addr);
heap.free(addr, 0);
heap.try_alloc(0x100000).with_result(
[&] (void *ptr) { heap.free(ptr, 0); },
[&] (Allocator::Alloc_error) { });
}
addr_t beg((addr_t)&blob_beg);