Skip to content

Comments

Rework allocator contract#1

Merged
Dramcryx merged 1 commit intomasterfrom
dev/improve-allocator
Nov 25, 2025
Merged

Rework allocator contract#1
Dramcryx merged 1 commit intomasterfrom
dev/improve-allocator

Conversation

@Dramcryx
Copy link
Owner

@Dramcryx Dramcryx commented Nov 25, 2025

To support proper deallocation, it is required that we store allocator somewhere through the whole coroutine lifetime. The issue is that we cannot just override delete - it is called after the promise_type destructor, meaning we cannot store allocator object there. Thus, we will do a default malloc trick - we will allocate longer block for the coroutine frame in which we will store the allocator object itself. This way, we will be able to restore allocator in delete so we don't need to rely on proper delete overload. Sadly, compiler does not propagate rvalue allocator no matter the type of the first argument of the coroutine we have, that's why we now need to require allocator to be copy-constructible. A respective recommendation to keep custom implementations lightweight is given in the concept brief.

Additionaly renamed example to ExampleDefaultTaskImpl and added a ExampleCustomAllocator which demonstrates how to specify custom allocator for the contract.

@Dramcryx Dramcryx force-pushed the dev/improve-allocator branch from 3b093f9 to 79a8924 Compare November 25, 2025 00:15
To support proper deallocation, it is required that we store allocator somewhere through the whole coroutine lifetime.
Sadly, compiler does not propagate rvalue allocator no matter the type of the first argument of the coroutine we have.
Thus, we will do a default malloc trick - we will allocate longer block for the coroutine frame in which we will store the allocator object itself.
This way, we will be able to restore allocator in delete so we don't need to rely on proper `delete` overload.
@Dramcryx Dramcryx merged commit 5088e6f into master Nov 25, 2025
4 checks passed
Dramcryx added a commit that referenced this pull request Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant