RosettaCodeData/Task/Arena-storage-pool/00-TASK.txt
2023-07-01 13:44:08 -04:00

29 lines
1.1 KiB
Text

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
<syntaxhighlight lang="ada">P := new T</syntaxhighlight>
where &nbsp; '''T''' &nbsp; is the type of an allocated object, &nbsp; and &nbsp; '''P''' &nbsp; is a [[reference]] to the object.
The storage pool chosen by the allocator can be determined by either:
* the object type &nbsp; '''T'''
* the type of pointer &nbsp; '''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:
# define an arena storage pool. &nbsp; An arena is a pool in which objects are allocated individually, but freed by groups.
# allocate some objects (e.g., integers) in the pool.
Explain what controls the storage pool choice in the language.
<br><br>