digitalmars.D - Miscellaneous memory management questions
- Peter Alexander (10/10) Sep 02 2010 Hi,
- Simen kjaeraas (31/40) Sep 02 2010 In a way, you don't. You can, however, replace it with a stub GC.
- Steven Schveighoffer (6/23) Sep 02 2010 You can disable it (for most intents and purposes) at runtime:
- Peter Alexander (17/26) Sep 03 2010 though.
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? 2. Can I override new? 3. Is the best (only?) way to do manual memory management to use scoped and emplace in conjunction with malloc and free? 4. Any plans for allocators? 5. Does Phobos rely on a GC? Thanks
Sep 02 2010
Peter Alexander <peter.alexander.au 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
Sep 02 2010
On Thu, 02 Sep 2010 09:31:22 -0400, Simen kjaeraas <simen.kjaras gmail.com> wrote:Peter Alexander <peter.alexander.au gmail.com> wrote:You can disable it (for most intents and purposes) at runtime: http://www.dsource.org/projects/druntime/browser/trunk/src/core/memory.d#L77Hi, 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.This is going to be deprecated. Use emplace instead. -Steve2. 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 ); } }
Sep 02 2010
== Quote from Simen kjaeraas (simen.kjaras gmail.com)'s articlePeter Alexander <peter.alexander.au gmail.com> wrote:Cool. So the stub GC does nothing and has no overhead?1. How do I disable the GC?In a way, you don't. You can, however, replace it with a stub GC.though.4. Any plans for allocators?None of which I know. D should easily support building your own,Of course, such a construct would then only be supported by yourownclasses.That's the problem though; if I write my own allocators then no one knows about them. I won't be able to use them with the standard library, so I'll have to rewrite all parts of the standard library that allocate memory (i.e. all the containers). What's worse, if I use some other 3rd-party library then it will use it's own allocators, which will probably be incompatible with mine. The whole point of a standard library is to provide a good set of common components that application and library developers can agree to build upon. If D is supposed to be a systems programming language, then I would expect allocators to be included in the standard library.See above.5. Does Phobos rely on a GC?Parts of it, certainly.
Sep 03 2010