[Cuis] serialization in Cuis

H. Hirzel hannes.hirzel at gmail.com
Sat Nov 7 08:49:21 CST 2015


Hello Nacho

Is it possible that your Cuis system does not show the class comments
for some reason?

Juan referred you to the class comment of ReferenceStream and the
subclass SmartreferenceStream.

The comment of class ReferenceStream below. It gives an example how to
store objects.

Regards
Hannes


---------------------------------
Comment of class ReferenceStream in Cuis 4.2-2563


This is a way of serializing a tree of objects into disk file. A
ReferenceStream can store
one or more objects in a persistent form, including sharing and cycles.

Here is the way to use DataStream and ReferenceStream:
	rr _ ReferenceStream fileNamed: 'test.obj'.
	rr nextPut: <your object>.
	rr close.

To get it back:
	rr _ ReferenceStream fileNamed: 'test.obj'.
	<your object> _ rr next.
	rr close.

ReferenceStreams can now write "weak" references. nextPutWeak:
writes a "weak" reference to an object, which refers to that object
*if* it also gets written to the stream by a normal nextPut:.

A ReferenceStream should be treated as a read-stream *or* as a
write-stream, *not* as a read/write-stream. The reference-remembering
mechanism would probably do bad things if you tried to read and write
from the same ReferenceStream.

[TBD] Should we override "close" to do (self forgetReferences)?

Instance variables
 references -- an IdentityDictionary mapping objects already written
	to their byteStream positions. If asked to write any object a
	second time, we just write a reference to its stream position.
	This handles shared objects and reference cycles between objects.
	To implement "weak references" (for Aliases), the references
	dictionary also maps objects not (yet?) written to a Collection
	of byteStream positions with hopeful weak-references to it. If
	asked to definitely write one of these objects, we'll fixup those
	weak references.
 objects -- an IdentityDictionary mapping relative byte stream positions to
	objects already read in. If asked to follow a reference, we
	return the object already read.
	This handles shared objects and reference cycles between objects.
 currentReference -- the current reference position. Positon relative to the
	start of object data in this file.  (Allows user to cut and paste smalltalk
	code from the front of the file without effecting the reference values.)
	This variable is used to help install each new object in "objects" as soon
	as it's created, **before** we start reading its contents, in
	case any of its content objects reference it.
 fwdRefEnds -- A weak reference can be a forward reference, which
	requires advance-reading the referrent. When we later come to the
	object, we must get its value from "objects" and not re-read it so
	refs to it don't become refs to copies. fwdRefEnds remembers the
	ending byte stream position of advance-read objects.
 skipping -- true if <what?>

If the object is referenced before it is done being created, it might
get created twice.  Just store the object the moment it is created in
the 'objects' dictionary.  If at the end, comeFullyUpOnReload returns
a different object, some refs will have the temporary object (this is
an unlikely case).  At the moment, no implementor of
comeFullyUpOnReload returns a different object except DiskProxy, and
that is OK.


On 11/7/15, Edgar J. De Cleene <edgardec2005 at gmail.com> wrote:
> As Juan said, ReferenceStream is your friend
> Here I attach a old cs
> If you wish , Foo saveOnFileNamed: 'Foo'create a Foo.obj file in your
> working directory.
> Later you could use readAndInspect: 'Path to your file'
> When you have DrgaAndDrop as my forked CuiSantafesino you could exchange
> working objects between Squeak,Cuis and Pharo.
> And if you said Pharo do not have ReferenceStream , well I made how to for
> Pharo 2.0 so is possible.
> With this technique I export and import objects big enough for have
> complete
> swiki into a Squeak derivate image, about 14 mb of data
> Cheers
>
> Edgar
> @morplenauta
>
>
>
>
> On 11/6/15, 3:48 PM, "Juan Vuletich" <juan at jvuletich.org> wrote:
>
>>  Hi Nacho,
>>
>>  Oh, yes, I misread. Ok. ReferenceStream and SmartRefStream are your
>> choices.
>> Take a look at the class comments, play with the examples. Ask questions.
>>
>>  Cheers,
>>  Juan Vuletich
>>
>>
>>  On 11/6/2015 3:42 PM, Ignacio Sniechowski wrote:
>>>
>>> Hi Juan,
>>>
>>> Thanks for your response.
>>>
>>> I¹m not trying to serialize classes but instances of them.
>>>
>>> Suppose theres a class called Memo with an ivar ³content²
>>>
>>> Then I want to be able add to the instances the posibility of storing
>>> their
>>> data.
>>>
>>> fileOut is great for classes I use it a lot!
>>>
>>> But I want a way to preserve data outside the image, so it can be loaded
>>> when
>>> a new image is used.
>>>
>>> thanks!
>>>
>>> Nacho
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>>  Ignacio Sniechowski
>>>
>>> Prosavic SRL
>>>  Sent with Airmail
>>>
>>>
>>>
>>>
>>> On November 6, 2015 at 3:13:25 PM, Juan Vuletich (juan at jvuletich.org)
>>> wrote:
>>>
>>>>
>>>>
>>>> Hi Nacho,
>>>>
>>>>  On 11/1/2015 11:45 PM, nacho wrote:
>>>>>  > Hi Folks,
>>>>>  > I'm trying to add support for serializing instances of a class.
>>>>>  > I'm looking at System-Object Storage
>>>>>  > And in particular to the class SmartRefStream which seems to add
>>>>> that
>>>>>  > functionality. However, the class has no comments and no examples.
>>>>>  > Is there some example which uses this class? a short demo? an
>>>>> example?
>>>>>  > Thanks in advance!!
>>>>>  > best
>>>>>  > Nacho
>>>>>  >
>>>>
>>>>  Are we browsing the same system? SmartRefStream class comment is 6016
>>>>  characters here. Superclass ReferenceStream has a class comments of
>>>> 2875
>>>>  characters. DataStream and ReferenceStream have class methods that
>>>> start
>>>>  with 'example'. Looking for references to these classes also brings
>>>>  useful examples of usage.
>>>>
>>>>  In any case, the usual way to serialize classes is fileOut. Why
>>>> doesn't
>>>>  this work for you? What problem are you trying to solve?
>>>>
>>>>  Cheers,
>>>>  Juan Vuletich
>>>>
>>>>
>>>>
>>>
>
>




More information about the Cuis mailing list