public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Lancelot SIX <lsix@lancelotsix.com>,
	Simon Marchi <simon.marchi@efficios.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/3] gdb: store internalvars in an std::vector
Date: Tue, 14 Feb 2023 13:41:03 -0500	[thread overview]
Message-ID: <748f35a2-bb69-2362-de5d-81481c4e408e@simark.ca> (raw)
In-Reply-To: <20230214105446.desfcw5xz5wpiqbt@octopus>

On 2/14/23 05:54, Lancelot SIX via Gdb-patches wrote:
> On Mon, Feb 13, 2023 at 11:21:37PM -0500, Simon Marchi via Gdb-patches wrote:
>> Change the storage of internalvars to an std::vector of unique pointers
>> to internalval.  This helps automate memory management, and will help
>> keep internalvars sorted in a subsequent patch.
>>
>> I initially tried to use an std::vector<internalval> initially, but some
>> parts of the code need for the addresses of internalvars to be stable.
>>
> 
> Hi Simon,
> 
> As the end-goal is to have an order, did you consider using a container
> which enforces it like a std::map?  For small number of objects (for
> some definition of small…) vector is usually more efficient but as here
> you hold pointers, I am not sure the vector brings a huge benefit.
> 
> You could use a std::map<std::string, internalvar> as the internalvar’s
> address will remain stable.  No need to have a unique_ptr.
> 
> One downside of the std::map is that you might end up with the name
> stored twice (once as key, and maybe still once in the internalvar
> object).  std::set can also be used, but with other downsides.

I had not thought of that, but I think it's a good idea.  Having the
name stored twice is not an issue, I think.

> The main difference with vector can come if we had 2 internal variables
> with the same name.  The current code does not prevent this AFAICT, but
> as one of the vars would effectively shadow the other, I am not sure
> this is a case we want to support anyway.

I don't think it can really happen today anyway.
create_internalvar_type_lazy is only used to create variable known in
advance, for which we know there are no clashes.  And through
lookup_internalvar, create_internalvar is only called after seeing that
there is no variable by that name.  So, I think we'll be fine with a
map.

Simon

      reply	other threads:[~2023-02-14 18:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  4:21 Simon Marchi
2023-02-14  4:21 ` [PATCH 2/3] gdb: use std::string for internalvar::name Simon Marchi
2023-02-14  4:21 ` [PATCH 3/3] gdb: keep internalvars sorted Simon Marchi
2023-02-14 10:54 ` [PATCH 1/3] gdb: store internalvars in an std::vector Lancelot SIX
2023-02-14 18:41   ` Simon Marchi [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=748f35a2-bb69-2362-de5d-81481c4e408e@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    --cc=simon.marchi@efficios.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).