Re: containers that own things they point to [Was: the correct way to delete a map]
On Nov 9, 11:39 am, Nick Keighley <nick_keighley_nos...@hotmail.com>
On 9 Nov, 09:38, James Kanze <james.ka...@gmail.com> wrote:
well obviously I can't disagree with your experience. But it seemed
not unusual for a container to own an object it pointed to. If you're
newing a lot of similar objects then you need to keep them somewhere.
Why not a container?
Perhaps it depends on the application, but most of the time, the
only objects I'm new'ing are entity objects, whose lifetime
depends on external phenomena. Typically, they will be in a map
(or two, or more), in the form of pointers in the map, but the
map doesn't "own" them; the map has a lifetime the same as that
of the entire program, and they remove themselves from the map
when they die.
The code that prompted my original query was a symbol table.
A definition file is parsed to build the symbol table
typedef std::map<std::string,const Type*> Table;
This symbol table is then used to decode a stream of data.
That sounds like it might be a reasonable case for the map to
own the data, yes, although it depends. I guess it's been too
long since I've worked on compilers. I did do a parser
recently, but it was for an interpreter---the data had to hang
around long after I'd finished parsing. But I can imagine
something like this when parsing XML, or something similar.
The first octet read is looked up to yield the message name,
which is then looked up to find the Type. Type knows how
to parse the rest of the stream.
Other cases might be Calls in a telecommunication system.
Calls tend to manage themselves, or be managed by one of the
termination points. One of the parties hangs up, which
generates an event, and processing this event terminates the
lifetime of the call. I can't see anyway that that would be
handled by a container.
Drawable items in a drawing program etc.
Same thing here, I think, although I'm much less familiar with
the domain. The drawable item is deleted by an erase event.
I'd have thought a container that owned things it pointed to
was very common!
I don't think so. Parsing seems to be an exception, and it
doesn't apply all of the time there.
James Kanze (GABI Software) email:firstname.lastname@example.org
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34