[prev in list] [next in list] [prev in thread] [next in thread] 

List:       antlr-dev
Subject:    [antlr-dev] [antlr-interest] V3 C++ backend writer
From:       jimi () temporal-wave ! com (Jim Idle)
Date:       2007-06-05 19:17:13
Message-ID: B36CCC332A32904F8FA3DE134A23533625267F () wavemachine ! temporal-wave ! com
[Download RAW message or body]



> -----Original Message-----
> From: Ric Klaren [mailto:ric.klaren at gmail.com]
> Sent: Tuesday, June 05, 2007 11:53 AM
> To: Loring Craymer
> Cc: Jim Idle; Terence Parr; antlr-dev list
> Subject: Re: [antlr-dev] [antlr-interest] V3 C++ backend writer
> wanted&ANTLR2 C++ backendmaintaine
> 
> Hi,
> 
> On 6/5/07, Loring Craymer <lgcraymer at yahoo.com> wrote:
> > Sounds like you are on the right track.  The big item
> > _not_ to do for ANTLR3 C++ support is smart (ref
> > counting) pointers.
> 
> Indeed the one in V2 is pretty vile.
> 
> > That was critical in ANTLR 2 to
> > avoid memory leaks because all AST nodes were created
> > and then many forgotten.
> 
> Indeed in v2 you really have to little control/knowledge over the
> codegen. Stringtemplate should make this a lot easier. Although if
> manual new/delete constructs are used it should be clearly documented
> where and when objects change ownership and whose responsibility it is
> to free them. And care should be taken to make this really consistent
> lest it turn into a maintenance nightmare (but I guess Jim gave
> already ample thought to that for the C runtime).

Yep, basically there is a factory that creates the various elements,
usually pre-allocating them in chunks of 'n'. It tracks the fact that it
allocated them but there is no reference counting. When you are
finished, you close the factory - it deallocates all memory it created.
Hence you can forget about tracking pointers and memory and the only
decision is whether you want to, say, copy your final tree or whatever,
then close the factories, or just wait until you are completely done
with the recognizer structures before closing anything (which is easiest
and should be the method you use unless you think the memory usage is
too much). When you want to create your own things in actions, then you
can use the factory and let it worry about it, or make your own. You
would do the latter if you feel that not getting rid of some of these
things as you go may cause too much memory use and it I,s for some
reason, not practical to just keep reusing a few of them.

Jim

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic