user
Dynamically allocated objects take their memory from a heap.

The memory for an object is provided by an **allocator** which maintains the storage pool used for the heap.

Often a call to allocator is denoted as

```
P := new T

```

where   **T**   is the type of an allocated object,   and   **P**   is a reference to the object.

The storage pool chosen by the allocator can be determined by either:

* the object type   **T**
* the type of pointer   **P**

In the former case objects can be allocated only in one storage pool.

In the latter case objects of the type can be allocated in any storage pool or on the stack.

Task

The task is to show how allocators and user-defined storage pools are supported by the language.

In particular:

1. define an arena storage pool.   An arena is a pool in which objects are allocated individually, but freed by groups.
2. allocate some objects (e.g., integers) in the pool.

Explain what controls the storage pool choice in the language.
assistant
(formerly Perl 6)

Raku is a high level language where, to a first approximation, everything is an object. Raku dynamically allocates memory as objects are created and does automatic garbage collection and freeing of memory as objects go out of scope. There is almost no high level control over how memory is managed, it is considered to be an implementation detail of the virtual machine on which it is running.

If you absolutely must take manual control over memory management you would need to use the foreign function interface to call into a language that provides the capability, but even that would only affect items in the scope of that function, not anything in the mainline process.

There is some ability to specify data types for various objects which allows for (but does not guarantee) more efficient memory layout, but again, it is considered to be an implementation detail, the use that the virtual machine makes of that information varies by implementation maturity and capabilities.