From: "André Pönitz" <apoenitz@trolltech.com>
To: gdb@sources.redhat.com
Subject: Re: GDB to C++ issue: deletion
Date: Fri, 01 Aug 2008 08:52:00 -0000 [thread overview]
Message-ID: <200808011054.24219.apoenitz@trolltech.com> (raw)
In-Reply-To: <200807312204.m6VM4JQM007611@tully.CS.Berkeley.EDU>
On Friday 01 August 2008 00:04:19 Paul Hilfinger wrote:
> Alpar wrote:
>
> > A good example for that was the debate on xfree vs. delete. One of the
> > goals of STL standard containers is that using them the programmer will
> > almost never has to use 'delete'.
>
> This reminded me of an issue that I'd be curious to see discussed.
> The STL container classes are certainly convenient for decreasing
> memory leaks with little fuss, but they do so internally with
> individual frees of allocated items. GDB currently does much of its
> allocation using a region-based style (in the form of obstacks). This
> reduces leakage at some expense in safety (although I have not seen
> many dangling-pointer problems triggered premature obstack releases in
> GDB). Allegedly, GDB's use of obstacks significantly speeds up
> allocation and (of course) deletion. I have certainly seen programs
> in which the need to free data structures individually adds
> significant cost*. The STL container classes provide for allocators,
> but I have no experience in how well they could be made to work in
> duplicating GDB's current performance in this area.
>
> I'd be interested in hearing the thoughts of the C++ lobby.
0. It's the wrong question ;-) It should not be "How to I translate the
code in lines 30 through 42 from C to C++?" but "The C code in lines
30 through 42 solves problem X. How would I solve X in C++?"
(yes, custom allocators might be a solution to certain generic
allocation performance problems, but the solution more often is
something different.)
1. The problem of finding alternatives does not exist ;-) If someone feels
- or, better, has proof - that good old C-style code provides the best
performance in some part of the code, and that part of the code
is on the critical path, well, than just leave that piece of code as it is.
Almost all C code is valid C++.
2. Even on this level, C++ might help to improve code readability and
maintanance by using e.g. helper classes with destructors etc. that
would translate to exactly the same machine code yet be more compact
on the source side.
3. Thirdly: Micro-optimizations. They are nice to improve the performance
of a piece of code _after_ one came to the conclusion that a certain
approach is conceptually the best and uses already the theoretically best
(or at least reasonable) data structures for the job. It's not uncommon to
gain a factor of 2 to 10 just by doing micro-optimizations, gaining half of a
percent at a time. So they are a valuable tool in the tool chest. However,
using them is a waste of resources if it's based on the wrong algorithm or
data structures.
Now, C code typically starts with linked lists as containers and improves
a bit on that and then applies micro optimizations in the "user code"
and than gets stuck at this level as refactoring of micro-optimized
code is difficult especially when the optimizations are inlined in the user
code and the algorithms/containers are tweaked away from "standard"
implementations.
With C++ one typically starts at least with the algorithm or container
that promises good scalability. That's easy, because "they are there".
Switching later is also comparatively easy, sometimes it's even sufficient
just to replace a single line to switch, say, from a std::list to a std::vector
or such. So C++ code is much more lilkely to use the right container
for the task, and using the wrong container typically costs a factor of "N"
not 2 or 10.
Incidentally, I think that the currently existing gdb (and other GNU core
tools) nicely demonstrate the problem from a user's perspective: It does
not scale well, and it has much worse performance than some competitors.
Of course, multi-platform abstraction has an price, but using e.g. quadratic
algorithms for an O(n) or O(n log n) task imply practical limits... see e.g.
http://sourceware.org/ml/binutils/2004-01/msg00476.html for an example]
André
[1] Of course, every now and then a Guru level coder shows up, replaces
one central trouble maker with something very cool, more efficient,
even more hand-crafted, that happens to work well without being
understood by aynone else. Then the Guru leaves, and the code becomes
a "no go" area for mere mortals...
next prev parent reply other threads:[~2008-08-01 8:52 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-10 18:46 Move GDB to C++ ? Stan Shebs
2008-07-10 19:01 ` Mark Kettenis
2008-07-10 20:01 ` Stan Shebs
2008-07-10 20:04 ` Paul Koning
2008-07-10 20:40 ` Andrew Cagney
2008-07-10 21:31 ` Stan Shebs
2008-07-10 22:30 ` Nick Roberts
2008-07-10 23:49 ` Stan Shebs
2008-07-11 6:14 ` Vladimir Prus
2008-07-11 12:40 ` Andrew Cagney
2008-07-11 12:23 ` Robert Dewar
2008-07-11 16:03 ` Dave Korn
2008-07-10 21:54 ` Mark Kettenis
2008-07-11 6:26 ` Joel Brobecker
2008-07-11 8:55 ` Vladimir Prus
2008-07-11 9:23 ` Andreas Schwab
2008-07-11 9:32 ` Vladimir Prus
2008-07-11 14:27 ` Andrew Cagney
2008-07-11 14:34 ` Daniel Jacobowitz
2008-07-11 14:54 ` Paul Koning
2008-07-11 15:30 ` Pedro Alves
2008-07-11 16:09 ` Dave Korn
2008-07-11 16:26 ` Daniel Jacobowitz
2008-07-12 5:41 ` Robert Dewar
2008-07-29 17:29 ` Andrew Cagney
2008-07-29 18:08 ` Vladimir Prus
2008-07-29 18:09 ` Thiago Jung Bauermann
2008-07-29 19:05 ` Andrew Cagney
2008-07-29 19:06 ` Thiago Jung Bauermann
2008-07-29 19:35 ` Thiago Jung Bauermann
2008-07-30 7:18 ` Vladimir Prus
2008-07-30 12:11 ` André Pönitz
2008-07-30 12:35 ` Mark Kettenis
2008-07-30 15:39 ` André Pönitz
2008-07-30 17:52 ` Eli Zaretskii
2008-07-30 17:47 ` Eli Zaretskii
2008-07-29 19:32 ` Eli Zaretskii
2008-07-29 19:45 ` Stan Shebs
2008-07-30 18:18 ` Eli Zaretskii
2008-07-30 19:05 ` Stan Shebs
2008-07-30 19:15 ` Eli Zaretskii
2008-07-30 19:42 ` Stan Shebs
2008-07-31 15:37 ` Andrew Cagney
2008-07-30 19:30 ` Andrew Cagney
2008-07-30 19:56 ` Mark Kettenis
2008-07-31 9:03 ` André Pönitz
2008-07-31 9:33 ` Alpár Jüttner
2008-07-31 10:07 ` Alpár Jüttner
2008-07-30 5:24 ` Tom Tromey
2008-07-30 18:30 ` Eli Zaretskii
2008-07-30 20:29 ` David Carlton
2008-07-30 20:30 ` Eli Zaretskii
2008-07-30 20:38 ` Eli Zaretskii
2008-07-31 4:52 ` Michael Veksler
2008-07-31 20:03 ` Ian Lance Taylor
2008-07-30 9:25 ` Vladimir Prus
2008-07-30 11:55 ` Salvatore Lionetti
2008-07-30 18:45 ` Eli Zaretskii
2008-07-30 19:19 ` Stan Shebs
2008-07-29 23:59 ` Mark Kettenis
2008-07-10 19:35 ` Jan Kratochvil
2008-07-10 22:41 ` Tom Tromey
2008-07-11 9:57 ` Andrew STUBBS
2008-07-11 11:44 ` Daniel Jacobowitz
2008-07-11 12:43 ` Pierre Muller
2008-07-11 13:14 ` Andrew Cagney
2008-07-13 23:18 ` Tom Tromey
2008-07-14 0:15 ` Nick Roberts
2008-07-14 8:49 ` Vladimir Prus
2008-07-14 13:21 ` Robert Dewar
2008-07-14 15:54 ` Vladimir Prus
2008-07-14 15:58 ` Robert Dewar
2008-07-14 16:03 ` Robert Dewar
2008-07-14 16:23 ` Vladimir Prus
2008-07-14 16:39 ` Robert Dewar
2008-07-14 17:53 ` Vladimir Prus
2008-07-16 19:06 ` Thiago Jung Bauermann
2008-07-14 17:54 ` Mark Kettenis
2008-07-14 16:12 ` Daniel Jacobowitz
2008-07-14 16:15 ` Robert Dewar
2008-07-14 16:18 ` Robert Dewar
2008-07-14 16:21 ` Bob Rossi
2008-07-14 16:31 ` Vladimir Prus
2008-07-14 19:00 ` Tom Tromey
2008-07-12 3:30 ` Michael Snyder
2008-07-14 14:54 ` Andrew Cagney
2008-07-20 14:36 ` Michael Eager
2008-07-31 8:40 ` Vladimir Prus
2008-07-31 14:37 ` Alpár Jüttner
2008-07-31 22:30 ` GDB to C++ issue: deletion Paul Hilfinger
2008-07-31 22:40 ` Daniel Jacobowitz
2008-07-31 22:58 ` Paul Hilfinger
2008-07-31 23:25 ` Daniel Jacobowitz
2008-08-01 5:38 ` Ian Lance Taylor
2008-08-01 8:52 ` André Pönitz [this message]
2008-08-01 9:53 ` Eli Zaretskii
2008-08-01 12:57 ` Daniel Jacobowitz
2008-08-01 14:57 ` Paul Koning
2008-08-01 15:31 ` Eli Zaretskii
2008-08-01 13:51 ` André Pönitz
[not found] ` <20080801125124.GA13594@caradoc.them.org>
[not found] ` <uzlnwn9jq.fsf@gnu.org>
2008-08-01 13:59 ` Daniel Jacobowitz
2008-08-01 15:17 ` Eli Zaretskii
2008-08-01 15:29 ` Daniel Jacobowitz
2008-08-01 15:38 ` Eli Zaretskii
2008-08-12 14:40 ` Problem with can_use_hw_breakpoint Jeremy Bennett
2008-08-12 14:51 ` Eli Zaretskii
2008-08-12 14:56 ` Jeremy Bennett
2008-07-31 20:00 ` Move GDB to C++ ? Eli Zaretskii
2008-08-01 13:13 ` Daniel Jacobowitz
2008-08-01 13:47 ` Eli Zaretskii
2008-08-01 14:04 ` André Pönitz
2008-08-01 15:20 ` Eli Zaretskii
2008-08-04 9:34 ` André Pönitz
2008-08-01 14:21 ` Daniel Jacobowitz
2008-08-01 15:23 ` Eli Zaretskii
2008-08-01 16:14 ` Vladimir Prus
2008-08-01 19:20 ` Eli Zaretskii
2008-08-02 5:55 ` Vladimir Prus
2008-08-02 8:07 ` Eli Zaretskii
2008-08-02 9:22 ` Vladimir Prus
2008-08-02 9:47 ` Eli Zaretskii
2008-08-02 10:00 ` Vladimir Prus
2008-08-02 10:16 ` Eli Zaretskii
2008-08-01 13:55 ` Mark Kettenis
2008-08-01 14:11 ` André Pönitz
2008-08-01 15:02 ` Stan Shebs
2008-08-01 15:05 ` Vladimir Prus
2008-08-01 15:17 ` Daniel Jacobowitz
2008-07-31 23:34 GDB to C++ issue: deletion Paul Hilfinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200808011054.24219.apoenitz@trolltech.com \
--to=apoenitz@trolltech.com \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox