Building, Heap partitions

Norman Feske norman.feske at ...1...
Thu Jan 28 10:53:54 CET 2010


Hi Peter,

> In trying to compile some code, i keep getting the following errors when i try
> to instantiate a genode thread:
> 
> undefined reference to `operator new[](unsigned int)'
> 
> Can I not use "new" to allocate memory? If not, what is the proper way of doing
> this via Genode?

the default 'new' and 'delete' are not provided by the framework to
raise awareness about memory allocations. The problem of the default
new operator is that it leaves open the question to whom the allocated
memory should be accounted. For example, a server that uses 'new' on
behalf of client requests would make its own heap usage dependent on
client behaviour and prone to resource-denial-of-service problems. In
Genode, we promote the concept that such a server allocates such memory
from a client-specific heap partition. More background information is
provided here

  http://genode.org/documentation/architecture/framework#Heap_partitioning

Because the standard 'new' operator does not support the concept of
heap partitions, we only provide a special 'new' operator that takes
an 'Allocator' as argument. This way, the programmer must specify where
to take the memory from. To allocate an object from the applications
own heap, you can use the heap allocator provided by the process
environment:

  A *a = new (Genode::env()->heap()) A(constructor_argument)

For destructing the object 'a', the allocator must be specified as well.
Because this is not possible with the delete operator, we provide a
'destroy' template in 'include/base/allocator.h'. Instead of 'delete a'
use:

  destroy(Genode::env()->heap(), a)

Despite of Genode not supporting standard 'new' and 'delete' by
intention, it is relatively easy to create those operators out of the
building blocks provided by Genode. For doing so, you may take a look at
the following examples:

  os/src/drivers/framebuffer/vesa/main.cc
  demo/src/app/scout/genode/platform_genode.cc (line 78)

Norman




More information about the users mailing list