memory management and the standard library

Olivier FAURE couteaubleu at gmail.com
Sat Mar 16 21:17:02 UTC 2019


On Saturday, 16 March 2019 at 20:17:50 UTC, Jacob Carlborg wrote:
> Instead of having a function allocate memory, pass a buffer, 
> delegate, output range or something similar to the function. 
> Then whatever you pass can decide if it should allocate using 
> the GC, malloc or something else.

It would have to be a delegate or an output range, because in 
most cases the callee wouldn't know in advance how much storage 
it needs to allocate.

Anyway, it would be pretty nice if there were a standardized way 
to tell a function how it should allocate its memory; it would 
allow some nice strategies like "I know that I'm going to discard 
most of what this function allocates, so just put in in a 
continuous buffer; then deep-copy the relevant data to GC memory, 
and throw the rest away" (eg in a parser).

However, for that to work, you'd probably need a way to pass 
implicit arguments to a function without having to specify 
`foobar(defaultGcAllocator, x, y, z)` every time you call a 
function.


More information about the Digitalmars-d mailing list