Reputation
4,365
Top tag
Next privilege 5,000 Rep.
Approve tag wiki edits
Badges
2 22 39
Newest
 Nice Answer
Impact
~239k people reached

Apr
27
awarded  Nice Answer
Mar
19
comment Is there any good search algorithm for a single character?
KMP is definitely not something I would call a "basic" string-matching algorithm... I'm not even sure it's such a fast either, but it's historically important. If you want something basic try the Z algorithm.
Mar
16
comment If my IDE is so smart, why do I need to cast “clone()”?
@JörgWMittag: I don't even think it's a question of whether advanced generics exist, it's a question of inheritance. Even if you have the generics that you mentioned then inheritance will still require you to re-implement a different instantiation of the Cloneable interface in order to get a sane signature which doesn't make a whole lot of conceptual sense...
Mar
16
comment If my IDE is so smart, why do I need to cast “clone()”?
Is the emphasis of your question on I or on 'cast "clone()"'? Because the question resulting from the former might actually be a much better question than from the latter.
Mar
13
awarded  Notable Question
Feb
16
comment Is functional programming faster in multithreading because I write things differently or because things are compiled differently?
Don't forget there's always a GC that has to run in the background and keep up with your allocation demands... and I'm not sure it's multithreaded...
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