-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef1b89c
commit 7382835
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Allocators | ||
|
||
The current implementation of coroutines implicitly allocates a coroutine - unless optimized - on the heap. | ||
As a result the user cannot initialize any coroutines using a custom allocator object. | ||
|
||
This means only static allocators can be supported. | ||
One way to costumize the allocation behaviour is via an extra template parameter `seq<T, AllocatorType>`. | ||
|
||
An alternative is to implement a costomization point using template specializations. | ||
|
||
We have chosen the latter solution as this does not require threading the AllocatorType through each operator. | ||
We believe that this reduces the cognitive overhead required to implement new algorithms and will increase developer productivity. | ||
This solution implies that you have to choose an allocator seq<T> before your application runs. | ||
|
||
## How does the customization point work? | ||
|
||
We have defined a generic type `template<class T> promise_allocator` which is used for each `seq<T>`. | ||
By default it uses the standard allocator. | ||
In order to change the promise_allocator specialize this template: | ||
|
||
```c++ | ||
template<class T> | ||
struct promise_allocator<seq<T>> { | ||
void* allocate(std::size_t); | ||
void deallocate(void*); | ||
}; | ||
``` | ||
This definition will be prefrred by the compiler as this a higher specificity compared to default definition. | ||
You can use a predifined allocator by just including `include/conduit/allocators/*.hpp` or implement your own in a same fashion. |