Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!EU.net!Germany.EU.net!news.maz.net!ins.net!heeg.de!gustav!hmm
From: hmm@gustav (Hans-Martin Mosner)
Subject: Re: BOSS and BlockClosure literals (VW 2.0)
Message-ID: <DLoEv6.492@heeg.de>
Sender: uucp@heeg.de
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
X-Newsreader: TIN [version 1.2 PL2]
References: <4e2bbc$l2m@info.epfl.ch>
Date: Wed, 24 Jan 1996 08:13:54 GMT
Lines: 49

Benoit GARBINATO (garbinat@lse.epfl.ch) wrote:
: I have the following problem when passing BlockClosure literals through BOSS:
: if a BlockClosure literal is defined in some method, BOSS produces a **huge**
: byte stream, including the method where the BlockClosure literal was defined.

: This always happens, no matter if the aforesaid BlockClosure literal is depen-
: dent on the enclosing method or not for its evaluation. In my case, all the 
: BlockClosure literals are fully parameterized, i.e., all they need to be evalua-
: ted is passed to them as paramters.

: Does anybody have an hint on how to get around this limitation ?
: Thanks in advance for your help.

The method of the BlockClosure has a reference to its outer method
(i.e., the method in which the BlockClosure is defined.)
This is needed for debugging, but not for executing the BlockClosure.
Here is a short example showing how to do it:

	| block bos fn |
	fn := 'test.bos' asFilename.
	bos := nil.
	"create a block (must be clean or copying)"
	block := [:x | x + 20].
	"break the outerMethod connection"
	block outerContext == nil
		ifFalse: [self error: 'only clean or copying blocks'].
	block method outerMethod: nil.
	"write the block"
	bos := BinaryObjectStorage onNew: fn writeStream.
	[bos nextPut: block] valueNowOrOnUnwindDo: [bos close].
	Transcript show: 'BOS file size: ', fn fileSize printString; cr.
	"read the block"
	bos := BinaryObjectStorage onOld: fn readStream.
	block := [bos next] valueNowOrOnUnwindDo: [bos close].
	"execute it"
	block value: 5

The file size for this example is 308 bytes, most of this is for the
BlockClosure class reference and associated symbols. When you store
more than just one BlockClosure in a BOS, you need significantly
less space for the additional BlockClosures.

Hans-Martin

--
+--- Hans-Martin Mosner -------- Senior Smalltalk Guru ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm@heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
