chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] serialization of functions, closures, continuations


From: felix winkelmann
Subject: Re: [Chicken-users] serialization of functions, closures, continuations
Date: Wed, 18 May 2005 08:38:42 +0200

On 5/16/05, Michele Simionato <address@hidden> wrote:
> Hi Felix, my subject says it all.
> 
> In Chicken:
> 
> 1. Can I serialize a function?
> 2. Can I serialize a closure?

No. A function/procedure/closure contains a pointer to compiled
C code and is built at run-time. Serialization into a file and subsequent
de-serialization would have to modify the code-pointer to the proper
value. Depending on the loaded symbols and linked in libraries
the locations of the code may vary wildly. 
One solution would be to compile a function-map into the code
and use these to convert code-pointers into some unique identifier
on serialization and do the reverse lookup on deserialization.

Oh, if I just had more time...

> 3. Can I serialize a continuation?
> 

See above (a continuation is just a special closure). One remark:
continuation serialization, even thoughj it is currently quite
fashionable, is IMHO somewhat questionable: estimating the size of a
continuation
is hard, even for someone who knows the implementation well. In
the worst case you drag in the whole global environment.

> In particular, if I could do 3, I could save my program on the disk and
> restart it later. I think this is impossible in general (i.e. if my program
> does input-output with some external source such as a database)
> but for self-contained programs it should be possible, right?

Yes, that would be handy. There are trade-offfs, though. Memory images
(like available in Smalltalk or in many CL, ML and Scheme systems)  tend
to accumulate garbage (unused global variables, etc.) and tend to be big.
On the other for certain applications, like taking a snapshot of a
computation and
continue it later, it would be practical. I experimented with unexec() a little,
but couldn't get anything to work.

> BTW, I cannot find anything in the manual about serialization.
> even for points 1 and 2.

There is no direct support for serialization yet. The lolevel unit has some
(low-level) operations for "evicting" data-structures into non-GC'd memory,
but this is crude and only applicable in certain situations.


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]