From: Tom Tromey <tom@tromey.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Tom Tromey <tom@tromey.com>,
Simon Marchi <simon.marchi@ericsson.com>,
gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] Introduce obstack_new, poison other "typed" obstack functions
Date: Thu, 26 Apr 2018 17:42:00 -0000 [thread overview]
Message-ID: <87lgd97tkt.fsf@tromey.com> (raw)
In-Reply-To: <129280589d474492d52e33e7997b47a7@polymtl.ca> (Simon Marchi's message of "Wed, 25 Apr 2018 22:58:03 -0400")
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
>> foo *f = new (obstack) foo ();
Simon> I thought about this. The downside I see is that it forces new to
Simon> allocate on an obstack. What if you want to use the standard new for
Simon> the same type in another context? Maybe this doesn't happen in
Simon> practice though.
Good point. We could have another mixin to provide a second operator
new, but that seems sort of ugly.
Simon> So if that was the main reason an obstack is used, you
Simon> might as well reconsider using an obstack at all [1]. But if the
Simon> obstack is used for the more efficient memory allocation, then it
Simon> would still make sense to use an obstack and track the objects
Simon> separately so that they can be destroyed properly. What we need is
Simon> (not sure this is realistic): everywhere we allocate an object on an
Simon> obstack and don't keep track of it for further destruction, have a
Simon> static_assert there that the type should be trivially destructible.
Yeah. And I'm not sure if this is doable either. Maybe if we removed
allocate_on_obstack and switched completely to your obstack_new, and
then made it static_assert is_trivially_destructible.
Simon> Or maybe there are better C++ ways of getting the same advantages as
Simon> with an obstack (efficient allocation for a bunch of objects
Simon> allocated/freed at the same time, data locality)?
I'm not totally sure that obstacks are so great. For example see
https://sourceware.org/bugzilla/show_bug.cgi?id=17143
In the past I think many times, something was put on the objfile obstack
simply because it was convenient. For example I know there were cases
where this was done with hash tables (even though hash resizing means
leaking storage) just because it was simpler than trying to find the
correct spot to clean up.
This aspect is certainly something we can do more easily now with C++ --
just make the members clean up after themselves.
Tom
prev parent reply other threads:[~2018-04-26 17:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-25 19:40 Simon Marchi
2018-04-25 19:40 ` [PATCH 2/2] Use XOBNEW when possible Simon Marchi
2018-04-25 22:27 ` Tom Tromey
2018-04-26 2:59 ` Simon Marchi
2018-04-25 22:36 ` [PATCH 1/2] Introduce obstack_new, poison other "typed" obstack functions Tom Tromey
2018-04-26 2:58 ` Simon Marchi
2018-04-26 17:42 ` Tom Tromey [this message]
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=87lgd97tkt.fsf@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@ericsson.com \
--cc=simon.marchi@polymtl.ca \
/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