home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:12296 comp.object:3195 comp.databases:6089
- Newsgroups: comp.lang.c++,comp.object,comp.databases
- Path: sparky!uunet!usc!sdd.hp.com!mips!darwin.sura.net!Sirius.dfn.de!math.fu-berlin.de!news.netmbx.de!netmbx!jrobie
- From: jrobie@netmbx.netmbx.de (Jonathan Robie)
- Subject: Re: A POET Tutorial
- Organization: netmbx, Berlin, Germany
- Date: Thu, 13 Aug 1992 07:28:44 GMT
- Message-ID: <HH150DN@netmbx.netmbx.de>
- References: <TCZ5DU@netmbx.netmbx.de> <9222615.24974@mulga.cs.mu.OZ.AU>
- Keywords: OODBMS, C++, POET
- Lines: 83
-
- fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
-
- >I have a couple of questions regarding Jonathan Robie's posting:
-
- >----------------------------------------------------------------------
-
- >> main ()
- >> {
- >> PtBase objbase;
- >>
- >> objbase.Connect ("LOCAL"); // Connect to the server
- >> objbase.Open ("test"); // Open the database
- >>
- >> Person *man = new Person(objbase);
- >> man->Store();
- >>
- >> objbase.Close();
- >> objbase.DisConnect();
- >> delete man;
- >> }
-
- >Why aren't Close() and DisConnect() automatically called by the
- >destructor?
-
- Each of these returns error codes which the programmer might want
- to test and respond to.
-
- >----------------------------------------------------------------------
-
- >> PersonAllSet* allPersons = new PersonAllSet("objbase");
- >> Person* thisPerson;
- >>
- >> allPersons->Seek(0, PtSTART);
- >> while (allPersons->Seek (1, PtCURRENT) == 0)
- >> {
- >> allPersons->Get(thisPerson);
- >> thisPerson->DoSomething();
- >> allPersons->Unget(thisPerson); // deletes the object if nobody
- >> // else is using it.
- >> }
- >> delete allPersons;
- >>
- >>[...]
- >>Note that we call Unget() when we are done with the object. Every
- >>object you read takes up memory, so you should get into this habit.
-
- >Again, weren't destructors invented so that we wouldn't have to rely
- >on programmers habits?
-
- What destructors are you talking about? The destructor for allPersons
- is not a good candidate, since it may sit around for a long time
- creating objects that you really don't want to keep in memory until
- the set is deleted, and using this destructor would make us keep
- track of all loaded objects in the allPersons set.
-
- The destructor for the object is also not a great candidate since
- it depends on programmer's habits just as much as the Unget() and
- has different semantics.
-
-
- >Also, is there any particular reason why allPersons is dynamically
- >allocated in this example? Wouldn't it be simpler and more efficient
- >to just use a local (automatic) variable?
-
- No particular reason...it all depends on how you are using it.
-
-
- Jonathan
-
- =======================================================================
-
- Jonathan Robie jrobie@netmbx.UUCP
- Arnold-Zweig-Str. 44 jrobie@netmbx.in-berlin.de
- O-1100 Berlin
- Deutschland Phone: +37 (2) 472 04 19 (Home, East Berlin)
- +49 (30) 342 30 66 (Work, West Berlin)
-
-
- --
- Jonathan
-
- ===========================================================================
-
-