Hi Bert,
No, we use ImageSegment directly (we’ve subclassed ImageSegment). Here’s the short version:
1. we copy the roots:
self
copyFromRoots: (Array with: anObject)
sizeHint: self fileSize // 2
areUnique: true.
2. we write the segment onto a MutliByteFileStream (which we’ve subclassed):
NSSegmentStream
forceNewFileNamed: fileName
do: [ :stream | stream writeObject: self ].
where #writeObject: is implemented as:
writeObject: anObject
(SmartRefStream on: self) nextPutObjOnly: anObject
We load the segment back by:
1. opening a MultiByteFileStream and sending the installation message:
NSSegmentStream
readOnlyFileNamed: (aDirectory fullNameFor: filename)
do: [ :stream |
self
installSegmentFrom: stream
andDo: aBlock ]
2. #installSegmentFrom:andDo: basically sends #readObject to the file stream:
readObject
"This is a hack to allow for the old segments (mixed code and objects)
to be loaded without the #inform: in #nextAndClose opening a UI element."
^ self binary peek = ReferenceStream versionCode
ifTrue: [ (SmartRefStream on: self) nextAndClose ]
ifFalse: [
| object |
self
ascii;
fileIn.
object := SmartRefStream scannedObject.
SmartRefStream scannedObject: nil.
object ]
3. and once we have the segment we send #install to it
We’ve made some modifications here and there (e.g. to suppress UI elements) but the above is the gist of it. I can give you the full source if you need it.
It’s possible that this is all overkill or parallels functionality found in other places. I’ve inherited the code and haven’t spent the time exploring improvements in that area.
Cheers,
Max
Eliot Miranda Mon, Oct 20, 2014 at 9:41 PM
Reply-To: Squeak Virtual Machine Development Discussion
To: Pharo Development List
Cc: Squeak Virtual Machine Development Discussion , The general-purpose Squeak developers list
On Mon, Oct 20, 2014 at 8:26 AM, stepharo wrote:
While I as a big fan of imageSegment and proposed to Mariano to work on imageSegment2 (it was the original idea for his phd)
he convinced us that imagesegment were not worth their complexity.
I absolutely agree.
So why do you want to have imageSegment?
Because of backwards-compatibility. If Spur does not provide image segments then the barrier to entry for Terf, eToys and Squeak may be too high. Spur is supposed to be a plug-in replacement for Cog, not something that requires lots of effort to port to.
Stef
stepharo Mon, Oct 20, 2014 at 9:55 PM
Reply-To: Pharo Development List
To: Pharo Development List
Sorry for breaking the stream. I could not find the email with thunderbird :(
Just for the record, you see what netstyle people did: they use image segment and they had to kill everything (like processes and others) because of
possible pointers so after saving a segment the image was basically dead because some escaping pointers to make a kind of memory leak.
Now they migrated to Fuel.
So now I think that people should better use Fuel. IS were nice at first but not when you look carefully to them, especially when you have
an object not in the roots pointing to an object inside the graph. Then you have to do a GC…. Mariano spent a year fighting with that
and his PhD is really nice.
Less magic, more stability, simpler VMs.
Because all the energy that you will put in something from the past will not be put in things for the future(not counting the bug hunting).
Stef
See also
Fuel serialization approach, BOSS (Binary Object Storage System), Parcels and ImageSegments