[PATCH][C++] Save memory and reallocations in name-lookup

Richard Guenther rguenther@suse.de
Mon Aug 20 07:24:00 GMT 2012


On Sat, 18 Aug 2012, Dimitrios Apostolou wrote:

> Hi,
> 
> On Fri, 17 Aug 2012, Jakub Jelinek wrote:
> > On Fri, Aug 17, 2012 at 06:41:37AM -0500, Gabriel Dos Reis wrote:
> > > I am however concerned with:
> > > 
> > > >   static void
> > > >   store_bindings (tree names, VEC(cxx_saved_binding,gc) **old_bindings)
> > > >   {
> > > > !   static VEC(tree,heap) *bindings_need_stored = NULL;
> > > 
> > > I would be more comfortable to see the cache be on per-scope
> > > (e.g. namespace scope) basis as opposed
> > > a blanket global cache stored in a global variable.
> > 
> > It is not any kind of cache.  It could be in theory an automatic variable
> > vector pointer, it is only used during that function.  The reason why it is
> > static variable instead is just to avoid constant allocation/deallocation
> > of the vector, this way after the first call it will be already allocated
> > (but, upon entry to store_bindings will always be empty).
> 
> Why not use stack vector of sufficient size for most cases then? I usually do
> something like:
> 
>       VEC (tree, stack) *bindings_need_stored = VEC_alloc (tree, stack, 32);
>       ...
>       VEC_free (tree, stack, bindings_need_stored);
> 
> if I've measured that 32 (or whatever) is enough for most cases. I don't have
> a clue about this case though.

I considered that, but I'm not sure it would be an improvement.  We'd
have a re-allocation and free in some cases then.

Richard.



More information about the Gcc-patches mailing list