Faster Virtual Method Dispatch
Sean Kelly
sean at f4.ca
Tue Apr 25 08:46:27 PDT 2006
Craig Black wrote:
>
> Hmmm. I have glanced at the word count example many times but was not aware
> of why it was faster in D until now. Is it really the GC paradigm that
> allows this performance? I think I'm beginning to finally see some method
> to the madness. Perhaps I need to rethink my stance on GC a little.
For what it's worth, the performance improvement may be attributed to
two factors: the C++ map class is a balanced binary tree while D uses a
hash table, and C++ indeed copies strings around while D passes references.
> It would seem then that GC can come out on top if there is a lot of sharing
> of allocated memory e.g. multiple references to each object. However, if
> you are certain that there will be only a single reference to each object,
> manual memory management should always outperform GC. Am I on the right
> track here?
D allows manual memory management as well, so you aren't forced to use
the GC if you don't want it in most cases. However, the lack of copy
ctors does essentially eliminate the possibility of using smart
pointers. One downside of a GC is that it needs to store bookkeeping
data, which may amount to as much as 50% memory overhead. This can be
problematic for very large applications.
Sean
More information about the Digitalmars-d
mailing list