Reputation
4,238
Top tag
Next privilege 5,000 Rep.
Approve tag wiki edits
Badges
2 21 38
Impact
~226k people reached

Jan
28
comment Demonstration of garbage collection being faster than manual memory management
Interesting. Are you saying you actually see people using shared pointers widely in industrial code even when using unique or even raw pointers is obviously better and requires no additional effort on their part? I ask because it seems to me that using shared pointers is both more effort and more inefficient -- i.e. I don't see why anyone would choose it in a situation where they could just as easily use a unique or raw pointer (like with isEmpty)
Jan
28
comment Demonstration of garbage collection being faster than manual memory management
You even have an assignment like ps = ps->next which adds unnecessary overhead given that ps is reference-counted. Note that "no garbage collection" does not mean "use reference counting everywhere". People who code in a language like C++ would only use reference counting where it is necessary, staying with single-owner pointers (e.g. unique_ptr) where possible. I would completely concede that littering my code with shared_ptr could slow it down far beyond how a GC'd equivalent might execute, but that's neither the claim nor the practice. I suspect this isn't the right comparison.
Jan
28
comment Demonstration of garbage collection being faster than manual memory management
So I reproduced your results, but the main trouble I'm having with your code is that I can't tell if it's actually an apples-to-apples comparison to the OCaml code -- I have no idea what kinds of optimizations OCaml can do. For example in C++ you constantly transfer ownership of pointers, which is totally unnecessary and typical C++ code would not do, but for example in OCaml a bit of escape analysis might be able to let the compiler bypass a lot of the reference counting bookkeeping, or to allocate something on the stack. Have you eliminated such potential sources of error?
Jan
28
comment Demonstration of garbage collection being faster than manual memory management
Thanks! Question: does OCaml implement closures the same way you've implemented them in C++? (i.e. are you sure it does not inline them, especially given that you've turned on optimizations?)
Jan
27
comment Demonstration of garbage collection being faster than manual memory management
I see. Can you tell me how to run the OCaml code? I don't know OCaml but I tried running it here and got a runtime error (and I'm not sure how to specify n either since I'm having trouble reading OCaml code).
Jan
27
comment Demonstration of garbage collection being faster than manual memory management
I'll take a look but right off the bat I can say I wouldn't expect shared_ptr to be the right thing to compare since it adds extra overhead for its own thread safety.
Jan
27
comment Demonstration of garbage collection being faster than manual memory management
+1 thanks. Where can we see and run the benchmark code?
Jan
15
comment Why does the documentation on some languages say “equivalent to” rather than “is”?
Note that what you see for find_if is not "the" documentation for C++. If it was, then the cast to bool (which you see in the answer below) would be wrong.
Jan
6
comment Demonstration of garbage collection being faster than manual memory management
@Ike : Deferring to a background thread is fine but then you also have to take into account how long (in real time, i.e. in seconds) the background thread is actively running on the CPU as well. Not doing so would be cheating since a manual scheme that doesn't use that CPU core would have been able to get higher performance by using that core. Also, since this is a practical question, I'm not looking for obscure edge cases such as custom C++ allocators that are specialized for one use case. We're just using the standard allocators in each implementation, not attempting to bypass them.
Jan
6
comment Demonstration of garbage collection being faster than manual memory management
@Ike: It's okay. See why I asked the question though? That was the entire point of my question -- people come up with all sorts of explanations that should make sense but everyone stumbles when you ask them to provide a demonstration that proves what they say is correct in practice. The entire point of this question was to once and for all show that this can actually happen in practice.
Jan
6
awarded  Nice Question
Dec
31
comment Does it make sense to use the term “Space Leak” with regard to Java?
+1 best answer here.
Dec
30
comment How can we be certain that the lower components of computer programming like compilers, assemblers, machine instructions, etc. are flawless?
+1 but somehow I doubt that "compilers and other core tools have similar ratios".
Dec
28
awarded  Yearling
Dec
18
comment What is the conceptual difference between finally and a destructor?
@dan04: Thanks so much, that's the perfect example for this. I could swear I'd come across so many situations where RAII didn't make sense but I had such a hard time thinking of them.
Dec
8
comment What is the conceptual difference between finally and a destructor?
I don't understand, my second example had nothing to do with throwing from a finally, so the fact that you think that's a bad idea should be irrelevant. (By which I mean, even if it never threw, the same argument would apply.)
Dec
8
comment What is the conceptual difference between finally and a destructor?
You never addressed these...
Dec
2
comment What is the conceptual difference between finally and a destructor?
Regarding your other arguments: "Would we really want to log the same thing irregardless?" Yes, it's just an example and you're kind of missing the point, and yes, no one ever prohibited from logging more specific details for each case. The point here is that you certainly can't claim there is never a situation in which you would want to log something that is common to both. Some log entries are generic, some are specific; you want both. And again, you're kind of completely missing the point by focusing on the logging. Motivating 10-line examples is hard; please try to not miss the point.
Dec
2
comment What is the conceptual difference between finally and a destructor?
What are your thoughts on my Javascript example?
Dec
2
comment What is the conceptual difference between finally and a destructor?
@sqykly: I don't understand, why do you say finally is just as wrong as a destructor? What do you think is the right way to achieve that kind of goal? Also, see my second example above. As it shows again, there really doesn't need to be a resource that needs to be released in the finally block.