3,619 reputation
21832
bio website
location
age
visits member for 4 years, 3 months
seen yesterday

May
3
comment If null is bad, why do modern languages implement it?
@MartinJames: The fewer invalid states your program has, the fewer ways it can be incorrect. Simple as that.
Apr
10
awarded  Notable Question
Mar
11
awarded  Notable Question
Feb
16
comment Does C# give you “less rope to hang yourself” than C++?
@supercat: Yeah, but the whole point here is that you can't rely on it behaving in any particular way for a generic implementation. This is in contrast to unspecified/implementation-defined behavior, where you can assume the behavior will be one of (potentially many) well-defined possibilities. That's a pretty subtle but also pretty critical difference.
Jan
3
awarded  Popular Question
Dec
28
awarded  Yearling
Dec
13
awarded  Popular Question
Jul
5
comment Demonstration of garbage collection being faster than manual memory management
I copied Raymond's code here, and to compare, I wrote my own version here. The ZIP file that contains the text file is here. On my computer, mine runs in 14 ms and Raymond's runs in 21 ms. Unless I did something wrong (which is possible), his 215-line code is 50% slower than my 48-line implementation, even without using memory-mapped files or custom memory pools (which he did use). Mine is half as long as the C# version. Did I do it wrong, or do you observe the same thing?
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
Oops sorry my bad. @btilly should read my comment then.
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@GuySirton: Then again, they don't even seem to be benchmarking GCs in the first place -- they seem to just be comparing C++ to Java, with preallocated storage...
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@GuySirton: I can't reproduce the keithlea.com/javabench results. I just tried out the heapsort implementation, and even when comparing the output of my old C++ compiler (Visual C++ 13.10.4035) with the one from JRE 7, C++ beats Java quite noticeably. If you can reproduce any of them let me know which one and I'll try that one.
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@delnan: Oh, I see what you mean now, that's a great point, thanks for bringing it up!
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@ddyer: Hmm, what exactly is so difficult to compare here? For example, let's say you're doing some computation (e.g. an FFT) on a lot of data (say, 100 million data points). A very easy and objective way to compare them would be to compare the number of data points processed per second, over the entire life of the program, and show that a GC is faster (or slower). That's a 100% objective and hard measure of performance, and the fact that there was a lot of data shows you're not measuring artifacts over small datasets. How is that hand-wavy? It seems perfectly comparable to me.
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
+1 for citing an actual example with code :) although proper use of C++ constructs (such as swap) isn't that hard, and would probably get you there quite easily performance-wise...
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@ddyer: So when people say (for example) "garbage collection is often faster than manual memory management", they're thinking of extreme examples like that? I find it hard to believe these statements (which are all over the web) require such extreme and difficult-to-demonstrate examples to be actually true...
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@btilly: How is that any different from calling abort() in the corresponding location in the C++ code?
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@btilly: "Write a program where the GC version fails to do a garbage run before exiting."... failing to do garbage collection in the first place is a memory leak due to the lack of a functioning GC, not a performance improvement due to the presence of a GC! That's like calling abort() in C++ before the program exits. It's a meaningless comparison; you're not even garbage-collecting, you're just letting memory leak. You can't say garbage collection is faster (or slower) if you're not garbage-collecting to begin with...
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@delnan: I don't see how you can have a "copy what the GC does" is possible though. A GC looks through the stack, static data segments, etc. in known locations to find references to the object graph's roots, but that's impossible in a native language C++ because there's no way to discover references like that, unless you make your own compiler (but then your code is restricted to that compiler).
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
If it's easy to construct an artificial example, would you mind showing a simple one?
Jul
4
comment Demonstration of garbage collection being faster than manual memory management
@DanPichelman: Machine performance. Examples of the claims I've seen are here.