I'm going to be the first to point out the one major flaw in this comparison: "plain C using GLib" is not comparable to "C++ standard library only" --- what should be compared is "C++ standard library only" and "C standard library only". Reimplementing pkg-config in pure C without GLib would be necessary for that. As for the "memory leaks" --- I haven't looked at the source, but something whose runtime is very short-…
> As for the "memory leaks" --- I haven't looked at the source, but something whose runtime is very short-lived, like pkg-config, may be very well justified in allocating and never freeing, letting the process exit itself be the "ultimate free". But sometimes the code grows and what was once a stand-alone executable is about to become a component in a larger executable. With C++ you get a correct component out of the…
Comparing C and C++ usage and performance with a real world project
81–90 of 140 posts
Re: Comparing C and C++ usage and performance with a real world project
#82If you ignore the protection mechanisms and the class heirarchy built into C++, then a C++ class is like a C struct that can contain function pointers. For many programs this is all that's needed, and the amount of overhead involved in using such an approach to creating objects is obviously lower. So there's no question C will always be faster. It's only when you need protection and class heirarchies that C++ benefit…
> a C++ class is like a C struct that can contain function pointers. No, it's not. Calling an ordinary class member function in C++ has exactly the same overhead as calling a function in C. Even virtual functions in C++ are not the same as putting function pointers in a C struct (they live in a separate data structure called the vtable). > the protection mechanisms and the class heirarchy All C++ protection mechanism…
Re: Comparing C and C++ usage and performance with a real world project
#83Earlier quoted context omitted.
> This makes sense, and then somebody has a vision for a use case beyond the original imagination, goes to turn the code into a library and spends countless hours smartening up lazy resource management. That's THEIR problem then. Why should the original author care for that?
> That's THEIR problem then. It is their problem, clearly. > Why should the original author care for that? That's the question. Don't you think it's easy to think of reasons, though? What if the person porting the code to a library was a later version of the original author?
Re: Comparing C and C++ usage and performance with a real world project
#84Earlier quoted context omitted.
> As for the "memory leaks" --- I haven't looked at the source, but something whose runtime is very short-lived, like pkg-config, may be very well justified in allocating and never freeing, letting the process exit itself be the "ultimate free". But sometimes the code grows and what was once a stand-alone executable is about to become a component in a larger executable. With C++ you get a correct component out of the…
bit of a tautology there. correct if correct.
Re: Comparing C and C++ usage and performance with a real world project
#85I'm going to be the first to point out the one major flaw in this comparison: "plain C using GLib" is not comparable to "C++ standard library only" --- what should be compared is "C++ standard library only" and "C standard library only". Reimplementing pkg-config in pure C without GLib would be necessary for that. As for the "memory leaks" --- I haven't looked at the source, but something whose runtime is very short-…
Reminds me of this anecdote I came across on the internets one time: https://groups.google.com/forum/message/raw?msg=comp.lang.ad...
Re: Comparing C and C++ usage and performance with a real world project
#86Earlier quoted context omitted.
It's true that generative programming can make up for shortcomings of C. But you're pretty much writing in two languages at that point, C and whatever spec generated the rest of the C code. It's not an apples-to-apples comparison to C++.
Well, some parts of the generative programming could be built into a tool and you probably wouldn't have to rewrite a generative program each time. So it's not really writing in 2 languages but using code generation to assist the programming process to reduce potential for error as a more flexible alternative to creating fixed constructs in a purpose built language.
Re: Comparing C and C++ usage and performance with a real world project
#87> Every manual resource deallocation call is a potential bug. This is confirmed by the number of memory leaks as reported by Valgrind. There are more than 1000 of them, several dozen of which are marked as "definitely lost". You can't compare performance If one program doesn't free memory, which obviously "saves" time. Valgrind can tell you where non-freed heap blocks have been allocated and a fix should not be compl…
In theory, theory and practice are the same. In practice, they aren't.
Re: Comparing C and C++ usage and performance with a real world project
#88Earlier quoted context omitted.
> a C++ class is like a C struct that can contain function pointers. No, it's not. Calling an ordinary class member function in C++ has exactly the same overhead as calling a function in C. Even virtual functions in C++ are not the same as putting function pointers in a C struct (they live in a separate data structure called the vtable). > the protection mechanisms and the class heirarchy All C++ protection mechanism…
Doesn't a vtable imply an extra level of indirection? You have to find where the vtable is in the object, then the function within the vtable, right? Is that not slower?
Re: Comparing C and C++ usage and performance with a real world project
#89I'm going to be the first to point out the one major flaw in this comparison: "plain C using GLib" is not comparable to "C++ standard library only" --- what should be compared is "C++ standard library only" and "C standard library only". Reimplementing pkg-config in pure C without GLib would be necessary for that. As for the "memory leaks" --- I haven't looked at the source, but something whose runtime is very short-…
The C++ standard library has more features though.
Re: Comparing C and C++ usage and performance with a real world project
#90Earlier quoted context omitted.
> That's THEIR problem then. It is their problem, clearly. > Why should the original author care for that? That's the question. Don't you think it's easy to think of reasons, though? What if the person porting the code to a library was a later version of the original author?
Will you also call them lazy because they didn't care about being thread safe or UTF8-ready?
I said it's lazy resource management. I'm really not trying to condemn, here, just provoke questions.