Memory/Allocation attributes for variables

sighoya sighoya at gmail.com
Sun Jun 6 10:19:46 UTC 2021


On Sunday, 6 June 2021 at 01:10:45 UTC, Elmar wrote:

> Goal: The responsibility of allocation is shifted from the 
> service, the callee, (which doesn't know about any concrete 
> client's allocation needs) to the client, the caller, (which 
> knows about it's own allocation needs and actually should know 
> what it gets).

That seems to very much resemble the idea odin strives for:

https://odin-lang.org/docs/overview/#implicit-context-system

It sounds very interesting and feels indeed system programming 
like, but I see some issues with that:

- the `new` call may not be the same for unique ptr, rc and gc as 
gc needs more context
- rc/arc may need to insert incs and decs to the begin and end of 
the scope respectively, but this would that means to templatize 
the callee or to box over a runtime option, both having draws
- overwriting allocators is an interesting concept, but how 
useful is this given that the code can't be re-adapted meaning 
not only the allocator make execution performant but also the 
code around it and both are intertwined to each other
- you have a small performance hit because of passing function 
pointer to the callee or by exchanging them when global vars are 
used for, it's akin to nondetermistic vs deterministic exception 
handling
- even more, how many custom allocators are passed to the callee 
because the callee as caller has many callees inside them which 
use allocation and all the custom allocators are propagating up.

I recognize that some minority is interested in this, even me to 
some kind. I'm still skeptical about the gain.
However, what is if you try to extend the compiler to see if it 
is possible, maybe you find other people to realize your idea.
Recalling myself, I know that russhy and IGotD are similar 
interested in custom allocators.



More information about the Digitalmars-d mailing list