home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12293 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  2.1 KB

  1. Xref: sparky comp.lang.c++:12293 comp.object:3193 comp.databases:6085
  2. Newsgroups: comp.lang.c++,comp.object,comp.databases
  3. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjh
  4. From: fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON)
  5. Subject: Re: A POET Tutorial
  6. Message-ID: <9222615.24974@mulga.cs.mu.OZ.AU>
  7. Keywords: OODBMS, C++, POET
  8. Sender: news@cs.mu.OZ.AU
  9. Organization: Computer Science, University of Melbourne, Australia
  10. References: <TCZ5DU@netmbx.netmbx.de>
  11. Date: Thu, 13 Aug 1992 05:05:46 GMT
  12. Lines: 53
  13.  
  14. I have a couple of questions regarding Jonathan Robie's posting:
  15.  
  16. ----------------------------------------------------------------------
  17.  
  18. >    main ()
  19. >    {
  20. >      PtBase    objbase;
  21. >    
  22. >      objbase.Connect ("LOCAL");    // Connect to the server
  23. >      objbase.Open ("test");        // Open the database
  24. >
  25. >      Person    *man = new Person(objbase);
  26. >      man->Store();
  27. >    
  28. >      objbase.Close();    
  29. >      objbase.DisConnect();
  30. >      delete man;
  31. >    }
  32.  
  33. Why aren't Close() and DisConnect() automatically called by the
  34. destructor?
  35.  
  36. ----------------------------------------------------------------------
  37.  
  38. >    PersonAllSet*    allPersons = new PersonAllSet("objbase");
  39. >    Person*    thisPerson;
  40. >
  41. >    allPersons->Seek(0, PtSTART);
  42. >    while (allPersons->Seek (1, PtCURRENT) == 0)
  43. >    {
  44. >    allPersons->Get(thisPerson);
  45. >    thisPerson->DoSomething();
  46. >    allPersons->Unget(thisPerson); // deletes the object if nobody 
  47. >                                  // else is using it.
  48. >    }
  49. >    delete allPersons;
  50. >
  51. >[...]
  52. >Note that we call Unget() when we are done with the object.  Every 
  53. >object you read takes up memory, so you should get into this habit.
  54.  
  55. Again, weren't destructors invented so that we wouldn't have to rely
  56. on programmers habits?
  57.  
  58. Also, is there any particular reason why allPersons is dynamically
  59. allocated in this example? Wouldn't it be simpler and more efficient
  60. to just use a local (automatic) variable?
  61.  
  62. -- 
  63. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  64. This .signature VIRUS is a self-referential statement that is true - but 
  65. you will only be able to consistently believe it if you copy it to your own
  66. .signature file!
  67.