This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: protected alloca class for malloc fallback




On 08/09/2016 03:17 PM, Aldy Hernandez wrote:
On 08/05/2016 01:55 PM, Richard Biener wrote:

Hi Richard.

Please don't use std::string.  For string building you can use obstacks.

Alright let's talk details then so I can write things up in a way you
approve of.

Take for instance simple uses like all the tree_*check_failed routines,
which I thought were great candidates for std::string-- they're going to
be outputted to the screen or disk which is clearly many times more
expensive than the malloc or overhead of std::string:

      length += strlen ("expected ");
      buffer = tmp = (char *) alloca (length);
      length = 0;
      while ((code = (enum tree_code) va_arg (args, int)))
    {
      const char *prefix = length ? " or " : "expected ";

      strcpy (tmp + length, prefix);
      length += strlen (prefix);
      strcpy (tmp + length, get_tree_code_name (code));
      length += strlen (get_tree_code_name (code));
    }

Do you suggest using obstacks here, or did you have something else in mind?

How about if it's something like the above but there are multiple exit
points from the function.  I mean, we still need to call obstack_free()
on all exit points, which is what I wanted to avoid for something as
simple as building a throw-away string.

I think that given our choice to switch to C++, we should use the language in idiomatic ways, and the standard library is part of that. Otherwise the language switch makes even less sense than it did in the first place.


Bernd


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]