home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!mcsun!sunic!kth.se!hemul.nada.kth.se!d88-jwa
- From: d88-jwa@hemul.nada.kth.se (Jon WΣtte)
- Subject: Re: TCL: Bizzare Behavior Time
- Message-ID: <1993Jan12.151637.10811@kth.se>
- Sender: usenet@kth.se (Usenet)
- Nntp-Posting-Host: hemul.nada.kth.se
- Organization: Royal Institute of Technology, Stockholm, Sweden
- References: <1993Jan11.170231.17969@fsl.noaa.gov> <1993Jan11.220137.26434@kth.se> <96325@rphroy.ph.gmr.com>
- Date: Tue, 12 Jan 1993 15:16:37 GMT
- Lines: 68
-
- In <96325@rphroy.ph.gmr.com> rrichter@link.ph.gmr.com (Roy Richter PH/32) writes:
-
- >|> CFoo :: DoFoo ( )
- >|> {
- >|> CBar * aBar = new CBar ;
- >|>
- >|> theBar = aBar ;
- >|> }
-
- >Do I have to be this nutso careful when dealing with TCL Objects?
-
- Yes, because TCL objects are all indirect (Handles)
- You never know when the address of the receiving variable
- is calculated. A possible scenario is that:
-
- theBar = new CBar ;
-
- 1) The address of theBar is calculated
- 2) new is called, which moves memory, and happens to
- move the calling object as well
- 3) the result is written into the address from 1) - BAD!
-
- You can also lock the object:
-
-
- CFoo :: DoFoo ( )
- {
- Boolean locked = Lock ( 1 ) ;
-
- TRY {
-
- theBar = new CBar ;
-
- } CATCH {
-
- Lock ( locked ) ;
-
- } ENDTRY ;
-
- Lock ( locked ) ;
- }
-
- Note that you HAVE to encapsulate in TRY/ENDTRY because
- otherwise an exception will leave your object locked and
- corrupt the heap!
-
- >And, does coding it like this protect me -- that is, is "theBar"
- >have a correct reference after the call to "new". If so, when does that
-
- Well, the stack can't move, so the temp variable will not
- move when memoryt moves, and a simple assignment will not
- move memory, so assignment to members is safe. Treat
- objects and ther members just as handles, and you'll be
- just fine!
-
- >refence get corrected? If
- > theBar = new CBar;
- >is potentially bad, maybe that should be somewhere in the docs.
-
-
- It _IS_ in the docs (read about indirect objects) and also in
- the sample code for the class library.
-
- --
- -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
-
- Clearly, most humans are not rational beings; they are rationalizing beings.
- -- Mel Walker
-