From: Simon Marchi <simon.marchi@polymtl.ca>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: GDB Patches <gdb-patches@sourceware.org>,
Pedro Alves <palves@redhat.com>,
Eli Zaretskii <eliz@gnu.org>
Subject: Re: [PATCH v2] Implement the ability to set/unset environment variables to GDBserver when starting the inferior
Date: Sat, 05 Aug 2017 18:14:00 -0000 [thread overview]
Message-ID: <7be6bdecb0da90c8b2efb550fc017a5e@polymtl.ca> (raw)
In-Reply-To: <87mv7f7x6t.fsf@redhat.com>
On 2017-08-05 01:03, Sergio Durigan Junior wrote:
> So, I've been thinking about this implementation over the last few
> days,
> but it's still a bit confuse to me. My C++-foo is not so good as
> yours,
> so maybe you can give me a hand.
>
> From what I understood initially, your intention was to make a new
> class
> that inherited from std::vector but overloaded/implemented methods to
> mimic what a std::set would do. However, after reading a bit, it
> doesn't seem like a good idea to inherit from std::vector (or any std
> containers). Which made me realize that maybe you are talking about
> creating a class that encapsulates a std::vector, without inheriting
> from it, and that provided the regular .push_back, .insert, .empty,
> etc., methods, but in an enhanced way in order to e.g. prevent the
> insert of duplicated elements, which is one of the things we miss from
> std::set.
Do you mean "... we miss from std::vector"?
I also read about inheriting STL containers. The danger is that they
don't have virtual destructors. So let's say we have gdb::set_vector
inheriting std::vector and try to delete a set_vector instance through a
vector pointer, the set_vector destructor won't be called. If
set_vector is simply adding some methods to the interface (no data
members, no user defined destructor), I don't know if this is really a
problem.
But now that I think of it, if we want to make sure this object
guarantees the properties of a set (like no duplicate elements), we
would have to hide most of the vector interface and only expose a
set-like interface. Otherwise, it would be possible to call push_back
and insert a duplicate element. Given that, I'd lean towards creating a
class that includes a vector and exposes a set-like interface, rather
than inheriting.
>
> Am I in the right direction here? Also, I started to think... I don't
> envision the user setting thousands of user-set environment variables,
> so *maybe* using std::set would be OK-ish for our use case scenario. I
> don't know. While I understand the concern about premature
> pessimization, I'm also not a fan of complicating the implementation
> just for a little bit of optimization either.
>
> WDYT?
Actually, if we expected the user to set thousands of environment
variables and needed it to be fast to set and unset variables, it would
be good to use std::set because of the O(log(N))
lookups/insertions/removals, which matters more when you have a lot of
elements. But when you just have a few elements, the constant cost is
more significant. A vector-based set would have O(N) complexity for
these operations (at least for insertions and removals, for lookups it
depends if it is sorted), which would be bad if we had thousands of
elements. But since we expect to have just a few, it would likely be
faster than std::set's constant cost.
But I agree with you that the important thing now is to get the
algorithm/functionality right. The typical use case is to have at the
maximum a few inferiors, which may have at the maximum a few environment
variables defined. The defined environment variables are only used when
doing a "run", which doesn't happen often. So in the end, I don't think
it would make a perceptible difference in memory usage or execution time
to use an std::set. If it helps to make the code significantly simpler,
then I think it's worth it. And we can always revisit it later by
making a drop-in replacement for std::set.
Simon
next prev parent reply other threads:[~2017-08-05 18:14 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-29 19:41 [PATCH] Implement the ability to transmit " Sergio Durigan Junior
2017-07-10 21:32 ` Sergio Durigan Junior
2017-07-13 21:47 ` Simon Marchi
2017-07-14 17:34 ` Sergio Durigan Junior
2017-07-27 3:36 ` [PATCH v2] Implement the ability to set/unset " Sergio Durigan Junior
2017-07-27 17:10 ` Eli Zaretskii
2017-07-27 22:05 ` Simon Marchi
2017-08-01 2:33 ` Sergio Durigan Junior
2017-08-01 9:35 ` Simon Marchi
2017-08-04 22:56 ` Sergio Durigan Junior
2017-07-29 22:36 ` Simon Marchi
2017-08-01 2:43 ` Sergio Durigan Junior
2017-08-01 9:54 ` Simon Marchi
2017-08-04 23:03 ` Sergio Durigan Junior
2017-08-05 18:14 ` Simon Marchi [this message]
2017-08-12 4:34 ` Sergio Durigan Junior
2017-08-12 8:11 ` Simon Marchi
[not found] ` <256083325d9f9c4cc4f5518fe6e5292d@polymtl.ca>
2017-08-12 4:19 ` Sergio Durigan Junior
2017-08-13 6:19 ` [PATCH v3] " Sergio Durigan Junior
2017-08-21 19:11 ` Sergio Durigan Junior
2017-08-24 19:25 ` Simon Marchi
2017-08-28 21:25 ` Sergio Durigan Junior
2017-08-28 23:13 ` [PATCH v4] " Sergio Durigan Junior
2017-08-31 19:37 ` Simon Marchi
2017-08-31 20:34 ` Sergio Durigan Junior
2017-08-31 20:39 ` Simon Marchi
2017-08-31 20:49 ` [PATCH v5] " Sergio Durigan Junior
2017-08-31 21:03 ` Simon Marchi
2017-08-31 21:26 ` Sergio Durigan Junior
2017-09-05 15:33 ` Thomas Preudhomme
2017-09-05 16:26 ` Simon Marchi
2017-09-05 17:09 ` Thomas Preudhomme
2017-09-05 18:41 ` Simon Marchi
2017-09-06 8:36 ` Thomas Preudhomme
2017-09-01 6:19 ` Eli Zaretskii
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=7be6bdecb0da90c8b2efb550fc017a5e@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=sergiodj@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