deprecated delete and manual memory management

Alexander aldem+dmars at nk7.net
Thu Apr 28 08:11:41 PDT 2011


On 28.04.2011 16:52, Steven Schveighoffer wrote:

>>   delete() is 99% of the cases O(1) operation (thanks to free lists),
> 
> Not exactly, it still needs to update the metadata for the block, which involves a binary search (O(lgn)) + you have to take the global lock, which means you could be making your multi-threaded application worse than a single-threaded one.

  Well, I was assuming that metadata is attached to the block - there is no need to search. Of course, it depends on implementation.

  OTOH, when there are deletes performed in a bunch (+ time to scan the data for references), it could really take time. Taking a lock, IMHO, is a bit less expensive comparing to pausing all threads. But I may be wrong...

> The point is that it runs infrequently enough to avoid hindering performance.

  Then there is another catch lurking around - the less frequently it runs, the more objects will be collected, so performance is hindered even more.

> D's GC is pretty horrible at performance, so there are definitely improvements yet to be seen there (David recently fixed some really bad ones, the next version of dmd
> should be much faster at allocation).

  Is it possible to adapt (or use directly) Boehm's GC? Just an idea...

> As mentioned, RT applications and OS kernels would need a specialized runtime, D does not support that with the current GC/runtime.  This does not mean that you would be using delete for those, you'd probably use a specialized runtime function using
> that specialized runtime.

  Right, but using "delete" is a bit more "natural". IMHO, of course :)

>>   Additionally, memory management hooks supported by the compiler are faster than any other solution (templates & co).
> 
> Absolutely untrue.  Runtime hooks cannot be inlined for instance.

  Unless compiler *knows* that there are hooks. Some believe that compiler must not handle anything specifically, but, to be really effective, this is difficult to avoid. Intrinsic functions are very useful.

> Having a dedicated keyword makes it seem sanctioned and promoted by the language, when in fact, it should almost never be used.

  D has some features which are discouraged anyway (like pointers & co.), but - D is a tool, and I believe that decision how to use a tool should be left to the user, that's all :)

/Alexander


More information about the Digitalmars-d mailing list