public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Trevor Saunders <tbsaunde@tbsaunde.org>
To: Oleg Endo <oleg.endo@t-online.de>
Cc: Jeff Law <law@redhat.com>,
	Richard Biener <richard.guenther@gmail.com>,
	Aldy Hernandez <aldyh@redhat.com>,
	Martin Sebor <msebor@gmail.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: protected alloca class for malloc fallback
Date: Tue, 09 Aug 2016 17:34:00 -0000	[thread overview]
Message-ID: <20160809174139.GA18239@ball> (raw)
In-Reply-To: <1470742429.639.196.camel@t-online.de>

On Tue, Aug 09, 2016 at 08:33:49PM +0900, Oleg Endo wrote:
> On Mon, 2016-08-08 at 13:39 -0400, Trevor Saunders wrote:
> 
> 
> > First sizeof std::string is 32 on x86_64, a char *, a size_t for the
> > length, and a 16 byte union of a size_t for allocated size and a 16 
> > byte buffer for short strings.  I suppose some of this is required by 
> > the C++ standard,
> 
> I recommend checking what others have figured regarding that matter
> https://github.com/elliotgoodrich/SSO-23

 I think one of the big mistakes in the C++ stl strings is that they try
 to shove stack allocated strings where you want an internal buffer for
 SSO and a class to put in structs into the same type.  imho it would be
 better to have std::string for the second use case, and a separate
 std::stack_string or something for the first case.

> >  but I doubt we really need to care about strings longer than 2^32 in
> > gcc.  If we put the length and allocated size in the buffer,
> > and have a separate class for stack allocated buffers I think we can 
> > have a string that is just sizeof void *.
> 
> This idea has one flaw in that it does not allow having objects by
> value.  It essentially *requires* one to *always* allocate them on the
> heap via new/delete.  Being able to store objects by value is useful in
> many situations.  So if you do the above, the next logical step that
> will follow is a smart-pointer-like wrapper that allows value
> semantics.  Because eventually somebody will want that operator == or
> operator < e.g. for associative containers.

 If what you want is the ability to put the buffer on the stack instead
 of the heap then I think a stack_string class that interoperates with
 your string class is the thing you want.

 I don't really see anything wrong with a string class being a really
 fancy smart pointer that has a bunch of useful string stuff on it.  As
 for operator == I'd be fairly ok with that, other than it hiding a O(N)
 operation in ==.

> > 
> > Second it would be useful performance wise to have a std::string_view
> > type class, but that is c++14 or 17? only so we'd need to import it 
> > into gcc or something.
> 
> http://en.cppreference.com/w/cpp/experimental/basic_string_view
> http://en.cppreference.com/w/cpp/string/basic_string_view
> 
> It's "funny" that GCC contains a C++ stdlib implementation and so
> little is actually used by GCC itself.

Regretably necessary sure, but I'm not sure its funny.  The first big
problem with using the stl is that the subset available in C++98 isn't
that great, you could maybe hack up libstdc++ so that you can use newer
types just without the bits that use newer language features, but that
would take some work.  The other big problem is that the stl is often
too general, and tries to be too simple.  std::string is actually a good
example of both of those problems.  There's really no reason it should
use size_t instead of uint32_t for the string length / capacity.  It
would also be a lot better if it had separate types for strings where
you want an internal buffer or don't.

Trev

  reply	other threads:[~2016-08-09 17:34 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 11:30 Aldy Hernandez
2016-08-04 12:58 ` Richard Biener
2016-08-04 15:19   ` Aldy Hernandez
2016-08-04 19:24     ` Jeff Law
2016-08-05 14:37       ` Aldy Hernandez
2016-08-05 15:15         ` Pedro Alves
2016-08-05 16:23         ` Jeff Law
2016-08-05 17:48           ` Richard Biener
2016-08-05  8:17     ` Richard Biener
2016-08-04 19:06 ` Pedro Alves
2016-08-04 19:16   ` Jeff Law
2016-08-04 19:22     ` Pedro Alves
2016-08-04 19:26       ` Jeff Law
2016-08-04 19:31         ` Pedro Alves
2016-08-05  2:10 ` Martin Sebor
2016-08-05 14:42   ` Aldy Hernandez
2016-08-05 17:56     ` Richard Biener
2016-08-05 18:16       ` Oleg Endo
2016-08-05 20:07         ` Richard Biener
2016-08-06 10:09           ` Aldy Hernandez
2016-08-06 10:15           ` Aldy Hernandez
2016-08-06 15:08             ` Richard Biener
2016-08-08 17:00               ` Jeff Law
2016-08-08 17:32                 ` Trevor Saunders
2016-08-08 19:03                   ` Richard Biener
2016-08-09 11:34                   ` Oleg Endo
2016-08-09 17:34                     ` Trevor Saunders [this message]
2016-08-10 17:03                       ` Oleg Endo
2016-08-11  1:23                         ` Trevor Saunders
2016-08-11 12:18                           ` Oleg Endo
2016-08-11 17:55                             ` Trevor Saunders
2016-08-20  2:29                         ` Mike Stump
2016-08-21 20:00                           ` C++11? (Re: protected alloca class for malloc fallback) Pedro Alves
2016-08-22  7:10                             ` Trevor Saunders
2016-08-22  7:28                               ` Richard Biener
2016-08-22 12:02                             ` Eric Gallager
2016-08-22 12:58                               ` Manuel López-Ibáñez
2016-08-22 22:08                               ` Mike Stump
2016-08-23 23:17                                 ` Eric Gallager
2016-08-09 13:17       ` protected alloca class for malloc fallback Aldy Hernandez
2016-08-09 13:21         ` Bernd Schmidt
2016-08-10 10:04         ` Richard Biener
2016-08-10 10:12           ` Aldy Hernandez
2016-08-10 10:39             ` Richard Biener
2016-08-10 18:00           ` Jeff Law
2016-08-10 18:33             ` Richard Biener
2016-08-16 16:28               ` Jeff Law
2016-08-16 16:44                 ` Jakub Jelinek
2016-08-16 16:47                   ` Jeff Law
2016-08-16 17:54                     ` Martin Sebor
2016-08-17  8:27                       ` Richard Biener
2016-08-17 13:39                         ` Martin Sebor

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=20160809174139.GA18239@ball \
    --to=tbsaunde@tbsaunde.org \
    --cc=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=msebor@gmail.com \
    --cc=oleg.endo@t-online.de \
    --cc=richard.guenther@gmail.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).