[cfe-commits] r101194 - /cfe/trunk/include/clang/AST/ASTVector.h

Ted Kremenek kremenek at apple.com
Wed Apr 14 08:22:50 PDT 2010


I think that's a valid concern; besides using an alternate data structure for InitListExprs one could also consider extending ASTVector (or something more generic) to recycle memory, regardless of the underlying allocator.  This could be done by passing something else other than ASTContext& to the ASTVector that manages the freelist and when necessary grabs new memory from ASTContext (or whatever is used for the underlying allocation).

Note that InitListExpr is not the only place where we use a "vector" in the ASTs, and in those cases we leak memory as well.

On Apr 14, 2010, at 4:59 AM, Benjamin Kramer wrote:

> 
> On 14.04.2010, at 01:39, Ted Kremenek wrote:
> 
>> Author: kremenek
>> Date: Tue Apr 13 18:39:09 2010
>> New Revision: 101194
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=101194&view=rev
>> Log:
>> Introduce ASTVector, which is a std::vector-like class that allocates all memory
>> using the allocator associated with an ASTContext.  This is largely copy-and-paste
>> from SmallVector, and should be refactored one day.
> 
> I was thinking about this before and came to the conclusion that a BumpPtrAllocator + vector is a
> bad combination. Every time the vector resizes the old memory isn't freed and adds up. I guess
> it doesn't matter in smaller cases but it could become a huge memory waste if we're not checking every
> ASTVector's insert characteristics carefully. In my opinion a list-like data structure should be
> preferred (where applicable).





More information about the cfe-commits mailing list