It does cost. It occupies a core that could be running your application.
|
The problem is, most applications can't utilise even two cores, and what about 4 cores of my laptop and 12 cores of my PC? We are soon facing a problem of having too many cores that have nothing to do.
But it really doesn't matter which core the allocation runs on, it still occupies processor time that could otherwise be used by the program
|
It doesn't matter only if your program is 100% scalable i.e. can utilize all the cores in 100%. This is almost never the case.
I don't see why. C++ can use multiple cores and gain advantages. |
Yes it can, but it is very hard to get to 100% CPU utilisation. Centralised allocator is often one reason for that. Also, parallel programming in C++ is really hard.
To illustrate this, lets do a challenge: create the most efficient program to compute factorial(500000) on a 4 core machine and let's compare the codes. Yours in C++, mine in any other language I choose. We will also check, if really CPU usage is 100% in this task - I seriously doubt that (both for C++, Java, and whatever you use).
BTW: I run your unmodified memory benchmark (the firs one, with arrays) in C++:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
g++ (GCC) 4.4.7 20110510 (prerelease) [svn/rev.173611 - mingw-w64/oz]
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\...\Temp\Testy>g++ -O3 -m64 alloc.cpp
C:\Users\...\Temp\Testy>a.exe
Run time: 2.761
C:\Users\...\Temp\Testy>a.exe
Run time: 2.854
C:\Users\...\Temp\Testy>a.exe
Run time: 2.854
C:\Users\...\Temp\Testy>a.exe
Run time: 2.808
|
Java version, modified with s/char/byte/, ran in 0.9 sec (already posted that). And keep in mind it zeroes the arrays, which C++ version doesn't do.