Memory management
Dukc
ajieskola at gmail.com
Sat Oct 3 04:32:08 UTC 2020
On Tuesday, 29 September 2020 at 10:57:07 UTC, novice3 wrote:
> Naive newbie question:
>
> Can we have (in theory) in D lang memory management like V lang?
>
I don't know V so can't be sure, but doing it the same way as in
the examples sounds possible.
The first two calls are easy. D string literals are stored in the
read-only memory that is uploaded together with the machine code
before execution. So the naive implementation wouldn't allocate
any more than the V version.
The third one is more difficult. To allocate without using GC or
RC means using an owning container, that releases memory when
exiting the scope. While they can be checked against leaking
referenced using the `-dip1000` feature, it's practical only when
the memory has a single clear owner and there is no need to store
references to it elsewhere. The GC and RC are better as a
general-purpose solution.
On the other hand, D could avoid all allocation in the third
example by using ranges. That would cause the printing function
to figure out the message as it prints.
More information about the Digitalmars-d-learn
mailing list