Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!hub.ucsb.edu!eiffel!nosmo From: nosmo@eiffel.UUCP (Vince Kraemer) Newsgroups: comp.lang.eiffel Subject: Re: eiffel and external c routines Summary: previous posting and correction Message-ID: <421@eiffel.UUCP> Date: 19 Oct 90 00:21:32 GMT References: <444@kepler1.kepler.com> Organization: Interactive Software Engineering, Santa Barbara CA Lines: 151 If you have been having trouble with the issue of using Eiffel objects in C code and have access to a fairly good archive of comp.lang.eiffel, I would suggest (re)reading message <391@eiffel.UUCP>, which covers the subject and agrees with the implementation of 2.2 (and 2.3). If you don't, I can post it again or mail it to you (depending on the demand). Another item covered in the cited article is the use of class MEMORY to deal with the disposal of externally allocated resources, when an object is garbage collected. Well, I hate to say it, but I believed the documentation in the class and the semantics that were discussed when this feature was being designed. In testing this feature, I discovered that it works, if you respect the following caveats, which are not documented: 1. The dispose will only work in DIRECT descendants of MEMORY only. 2. The dispose feature is only called when the routine MEMORY.full_collect is called (not MEMORY.collect is called or when the collection is triggered automatically). This does limit the applicability of using dispose or of automatic memory management considerably. There is a caveat, for those who can still make good use of dispose, to apply when writing dispose routines: DO NOT apply remote notation (dots) to attributes. There is no order implied in the collection of garbage. This means that it is possible that an attribute of an object has been collected before it client. Trying to dereference the collected object will raise an exception. I wish to apologize to all those who may have been mislead by my previous posting. I have learned my leason though: test then post. The following shar file has a system to illustrate the use of dispose (correctly). Vince Kraemer ISE Tech. Support (technical correspondence to: eiffel@eiffel.com) ----------------------------- sh-archive ------------------------------- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by geneve!nosmo on Thu Oct 18 17:12:48 PDT 1990 # Contents: a.e driver.e .eiffel echo x - a.e sed 's/^@//' > "a.e" <<'@//E*O*F a.e//' --|--------------------------------------------------------------- --| Copyright (C) Interactive Software Engineering, Inc. -- --| 270 Storke Road, Suite 7 Goleta, California 93117 -- --| (805) 685-1006 -- --| All rights reserved. Duplication or distribution prohibited -- --|--------------------------------------------------------------- --| Author: Vincent Kraemer @ Interactive Software Engineering --| Created: Thu Oct 18 09:26:43 1990 class A export inherit MEMORY redefine dispose; feature a1, a2, a3, a4: integer; dispose is do -- The use of io will be okay since it is shared. -- all others you must be careful about. io.putstring ("Disposing of an A."); io.new_line; end; end -- class A @//E*O*F a.e// chmod u=rw,g=rw,o=r a.e echo x - driver.e sed 's/^@//' > "driver.e" <<'@//E*O*F driver.e//' class DRIVER export inherit MEMORY feature hold: ARRAY [A]; Create is local an_a: A; ol, il: integer; do io.putstring ("Now using manual storage control."); io.new_line; collection_off; from ol := 0 until ol = 200 loop io.putstring ("second test: "); io.putint (ol); io.new_line; hold.create (0, 100000); from il := 0; until il > 100000 loop an_a.create; hold.put (an_a, il); il := il + 1; end; ol := ol + 1; hold.forget; full_collect; collection_off; end; end; end -- class DRIVER @//E*O*F driver.e// chmod u=rw,g=rw,o=r driver.e echo x - .eiffel sed 's/^@//' > ".eiffel" <<'@//E*O*F .eiffel//' ------------ EIFFEL SYSTEM DESCRIPTION FILE ------------------- -- For simple uses, just replace ``root_class_name'' below -- by the name of the root class of your system (lower case) ROOT: driver UNIVERSE: /usr/local/Eiffel/library/support EXTERNAL: NO_ASSERTION_CHECK (N): PRECONDITIONS (Y): ALL ALL_ASSERTIONS (N): DEBUG (N): TRACE (N): OPTIMIZE (N): GARBAGE_COLLECTION (y) C_PACKAGE (N): C_EXTERNAL: MAKE: VISIBLE (N): ---------------------------------------------------------------- @//E*O*F .eiffel// chmod u=rw,g=rw,o=r .eiffel exit 0