Miscellaneous memory management questions
Simen kjaeraas
simen.kjaras at gmail.com
Thu Sep 2 06:31:22 PDT 2010
Peter Alexander <peter.alexander.au at gmail.com> wrote:
> Hi,
>
> I've not been staying up to date on the new/delete discussions and
> related memory management issues, so I have a few questions.
>
> 1. How do I disable the GC?
In a way, you don't. You can, however, replace it with a stub GC.
According to http://dsource.org/projects/druntime/wiki/GettingStarted:
"If you want to change the GC implementation used by the druntime, you
have to change the src/dmd-posix.mak (or src/dmd-win32.mak for Windows),
search for DIR_GC variable and change it from basic to whatever you want,
for example, the stub implementation:
DIR_GC=gc/stub
Then, rebuild as shown in the previous section.
Right now there are only 2 implementations: stub and basic, so unless you
will be working on your own implementation, there is no much point on
changing this =)"
in /src/druntime/src/gcstub under your dmd installation, there should be
a file gc.d, containing a simple garbage collector. This may or may not
need customization to fit your exact needs.
> 2. Can I override new?
Yes. However, this is no longer mentioned on
http://digitalmars.com/d/2.0/class.html, so it might be intended not to
be there anymore.
class foo {
new( uint size ) {
return malloc( size );
}
}
> 3. Is the best (only?) way to do manual memory management to use scoped
> and emplace in conjunction with malloc and free?
Yes. Add helper functions, allocators and whatever else you may feel
necessary, as you like.
> 4. Any plans for allocators?
None of which I know. D should easily support building your own, though.
Of course, such a construct would then only be supported by your own
classes.
> 5. Does Phobos rely on a GC?
Parts of it, certainly.
--
Simen
More information about the Digitalmars-d
mailing list