r/cpp • • Sep 15 '26

Asynchronous API

https://grishavanika.github.io/async_api.html
36 Upvotes

28 comments sorted by

View all comments

Show parent comment

4

u/robertahleahy WG21, SCC, std::execution, Finance Sep 20 '26

The standard library is already full of memory allocations, so clearly 'generality' is not a concern.

There's a difference between allocations when they're required (e.g. std::vector) and when they're not (e.g. asynchrony).

Because this 'pessimisation' bring both benefits (it establishes a communication channel that serves a real purpose), and reduces a significant cognitive cost.

You don't need an allocation for a communication channel, and depending on the modality of communication the establishment of such a channel might be contraindicated.

Also I disagree that it reduces cognitive cost. Maybe in the marginal case (i.e. a single asynchronous operation) but not in the compositive case. Trying to make a well-behaved system out of unstructured concurrency is a nightmare, whereas with structured concurrency it's the naturally emergent property.

nor is there any lack of structure.

If you had structure you'd know which actor would release the resource last and when that would happen, and therefore wouldn't need shared_ptr.