Re: Silver bullet for C++ memory management ?
<joshuamaurice@gmail.com>
?[A]llocation in modern JVMs is far faster than the best
performing malloc implementations. ...
As I see it, it must be one of:
1- the above studies must have ignored crucial details in arriving in
such blatantly wrong conclusions,
2- current malloc implementations really really suck,
or 3- There is something I'm unaware of which greatly pessimizes
malloc performance. (I don't think so.)
....
There can be some accidents.
I recall from the past AA or HS measured performance for some stuff in CUJ,
and the used MS version sucked. (around MSVC 4 or 5?)
Turned out it had a 'broken' operator new in the library. It was a nice
while() loop calling new_handler on the failure branch. To do that the
address was retrieved from the thread context, that used mutexes and
everything. Stuff not needed for the common case when allocation
succeeds...
The next version it was corrected, the loop started only after a first
failure resulting the execution be several times faster.
For the other thing: allocation from a GC heap is really fast, it is like
allocation of locals on stack -- all you do is increment one pointer. (When
you have free space).
Regular malloc must traverse the free blocks list to find a big-enough block
to serve the request, it may not be the first, and afterwards fill 2-3
fields.
So yes, until collection the GC alloc is faster. In isolation. Whether the
allocation's time itself is measurable besides the other operation is
another story.
And even after colelction time is put back in the equation, we have another
difference: in java all the objects must use the heap, while in C++ many of
them is local, never going for heap.
In practice then anyone can see for himself how stuff performs. I used
Azureus for long time, that was fancier than BitComet, so I ignored that it
used 3 times as much memory for the same work. Then eventually changed to
uTorrent. Why waste 50-80 megs of memory really?
I use AgroUML: it shows the heap and compact operations in the status bar.
Good evidence that it plays compact all the time.
IMO java has the advantage of portability, for that gain we tend to swallow
the still existing cost in resource usage -- but denying those cost in
general sounds ridiculous.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]