public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Aldy Hernandez <aldyh@redhat.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	 Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [PATCH] irange_pool class
Date: Thu, 17 Sep 2020 21:43:56 -0400	[thread overview]
Message-ID: <8b999eaf506d993b00edda3419dd82d6ad8df170.camel@redhat.com> (raw)
In-Reply-To: <d7195b01-424e-3ec0-b16a-845d29eccda7@redhat.com>

On Thu, 2020-09-17 at 12:36 +0200, Aldy Hernandez via Gcc-patches
wrote:
> This is the irange storage class.  It is used to allocate the
> minimum 
> amount of storage needed for a given irange.  Storage is
> automatically 
> freed at destruction.
> 
> It is meant for long term storage, as opposed to int_range_max which
> is 
> meant for intermediate temporary results on the stack.
> 
> The general gist is:
> 
> 	irange_pool pool;
> 
> 	// Allocate an irange of 5 sub-ranges.
> 	irange *p = pool.allocate (5);
> 
> 	// Allocate an irange of 3 sub-ranges.
> 	irange *q = pool.allocate (3);
> 
> 	// Allocate an irange with as many sub-ranges as are currently
> 	// used in "some_other_range".
> 	irange *r = pool.allocate (some_other_range);

FWIW my first thoughts reading this example were - "how do I deallocate
these iranges?" and "do I need to call pool.deallocate on them, or is
that done for me by the irange dtor?"

I think of a "pool allocator" as something that makes a small number of
large allocation under the covers, and then uses that to serve large
numbers of fixed sized small allocations and deallocations with O(1)
using a free list.

[...]

> +// This is the irange storage class.  It is used to allocate the
> +// minimum amount of storage needed for a given irange.  Storage is
> +// automatically freed at destruction.

"at destruction" of what object - the irange or the irange_pool? 
Reading the code, it turns out to be "at destruction of the
irange_pool", and it turns out that irange_pool is an obstack under the
covers (also called a "bump allocator") and thus, I believe, the
lifetime of the irange instances is that of the storage instance.

I think it would be clearer to name this "irange_obstack", or somesuch.

> +//
> +// It is meant for long term storage, as opposed to int_range_max
> +// which is meant for intermediate temporary results on the stack.
> +
> +class irange_pool
> +{
> +public:
> +  irange_pool ();
> +  ~irange_pool ();
> +  // Return a new range with NUM_PAIRS.
> +  irange *allocate (unsigned num_pairs);
> +  // Return a copy of SRC with the minimum amount of sub-ranges
> needed
> +  // to represent it.
> +  irange *allocate (const irange &src);
> +private:
> +  struct obstack irange_obstack;

...and thus to rename this field to "m_obstack" or similar.

[...]

Hope this is constructive
Dave


  parent reply	other threads:[~2020-09-18  1:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 10:36 Aldy Hernandez
2020-09-17 18:02 ` Martin Sebor
2020-09-18  6:17   ` Aldy Hernandez
2020-09-18  1:43 ` David Malcolm [this message]
2020-09-18  5:49   ` Aldy Hernandez
2020-09-18 12:28     ` David Malcolm
2020-09-18 14:10       ` Aldy Hernandez
2020-09-18 17:07         ` Martin Sebor
2020-09-18 17:36           ` Andrew MacLeod
2020-09-18 20:35             ` Martin Sebor
2020-09-18 21:09               ` Andrew MacLeod
2020-09-19 20:32                 ` Martin Sebor
2020-09-20  0:40                   ` Andrew MacLeod
2020-09-20  7:01                   ` Aldy Hernandez
2020-09-21 14:14                   ` Andrew MacLeod
2020-09-18 16:42       ` Andrew MacLeod
2020-09-18 17:03         ` Aldy Hernandez
2020-09-28 15:56           ` Andrew MacLeod

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=8b999eaf506d993b00edda3419dd82d6ad8df170.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).