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

  1. Xref: sparky comp.lang.c++:12296 comp.object:3195 comp.databases:6089
  2. Newsgroups: comp.lang.c++,comp.object,comp.databases
  3. Path: sparky!uunet!usc!sdd.hp.com!mips!darwin.sura.net!Sirius.dfn.de!math.fu-berlin.de!news.netmbx.de!netmbx!jrobie
  4. From: jrobie@netmbx.netmbx.de (Jonathan Robie)
  5. Subject: Re: A POET Tutorial
  6. Organization: netmbx, Berlin, Germany
  7. Date: Thu, 13 Aug 1992 07:28:44 GMT
  8. Message-ID: <HH150DN@netmbx.netmbx.de>
  9. References: <TCZ5DU@netmbx.netmbx.de> <9222615.24974@mulga.cs.mu.OZ.AU>
  10. Keywords: OODBMS, C++, POET
  11. Lines: 83
  12.  
  13. fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  14.  
  15. >I have a couple of questions regarding Jonathan Robie's posting:
  16.  
  17. >----------------------------------------------------------------------
  18.  
  19. >>    main ()
  20. >>    {
  21. >>      PtBase    objbase;
  22. >>    
  23. >>      objbase.Connect ("LOCAL");    // Connect to the server
  24. >>      objbase.Open ("test");        // Open the database
  25. >>
  26. >>      Person    *man = new Person(objbase);
  27. >>      man->Store();
  28. >>    
  29. >>      objbase.Close();    
  30. >>      objbase.DisConnect();
  31. >>      delete man;
  32. >>    }
  33.  
  34. >Why aren't Close() and DisConnect() automatically called by the
  35. >destructor?
  36.  
  37. Each of these returns error codes which the programmer might want
  38. to test and respond to.
  39.  
  40. >----------------------------------------------------------------------
  41.  
  42. >>    PersonAllSet*    allPersons = new PersonAllSet("objbase");
  43. >>    Person*    thisPerson;
  44. >>
  45. >>    allPersons->Seek(0, PtSTART);
  46. >>    while (allPersons->Seek (1, PtCURRENT) == 0)
  47. >>    {
  48. >>    allPersons->Get(thisPerson);
  49. >>    thisPerson->DoSomething();
  50. >>    allPersons->Unget(thisPerson); // deletes the object if nobody 
  51. >>                                  // else is using it.
  52. >>    }
  53. >>    delete allPersons;
  54. >>
  55. >>[...]
  56. >>Note that we call Unget() when we are done with the object.  Every 
  57. >>object you read takes up memory, so you should get into this habit.
  58.  
  59. >Again, weren't destructors invented so that we wouldn't have to rely
  60. >on programmers habits?
  61.  
  62. What destructors are you talking about?  The destructor for allPersons
  63. is not a good candidate, since it may sit around for a long time
  64. creating objects that you really don't want to keep in memory until
  65. the set is deleted, and using this destructor would make us keep
  66. track of all loaded objects in the allPersons set.
  67.  
  68. The destructor for the object is also not a great candidate since
  69. it depends on programmer's habits just as much as the Unget() and
  70. has different semantics.
  71.  
  72.  
  73. >Also, is there any particular reason why allPersons is dynamically
  74. >allocated in this example? Wouldn't it be simpler and more efficient
  75. >to just use a local (automatic) variable?
  76.  
  77. No particular reason...it all depends on how you are using it.
  78.  
  79.  
  80. Jonathan
  81.  
  82. =======================================================================
  83.  
  84. Jonathan Robie        jrobie@netmbx.UUCP
  85. Arnold-Zweig-Str. 44    jrobie@netmbx.in-berlin.de
  86. O-1100 Berlin        
  87. Deutschland        Phone:  +37 (2) 472 04 19  (Home, East Berlin)
  88.                 +49 (30) 342 30 66 (Work, West Berlin)
  89.  
  90.  
  91. -- 
  92. Jonathan
  93.  
  94. ===========================================================================
  95.  
  96.