Serializing objects that have references to functions (anyone know how)?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Serializing objects that have references to functions (anyone know how)?

Jordo Odroj
Hi Haxers,

I ran into a problem when serializing an object that had a reference to a function pointer. I understand the limitation. The function's true behavior is not only the code, but the data environment packaged into a closure. In my case, I knew that the function was not using any data in the closure but rather I had the following two situations:
1. The function was a method of an object:
2. In another situation, the function was just a helper handler (think static function of some helper class).

It seems like in both of these situations, it is, in fact practical to serialize the functions. In the case of one, we'd be serializing "the object the method is attached to" + "information about what method to invoke". In other words (as I've known for some time), Objects are really just very organized closures, we can serialize objects, why can't we serialize references to members that depend on their existence?
I could understand the difficulty in serializing arbitrary closures, but the object method case seems much more attainable, as the closures are well-known (they are only limited to the object (IIRC in haxe)).

For all the NON-Object methods, I could see being required to mark certain methods with @non-closure. Wouldn't this help many performance concerns? Would this just be equivalent with "inline"? 

The way I got around the problem for now, is by using the delegate pattern, common in Cocoal/OSX development. You simply define an interface "interface SomeEventHandler { function handleThing() : Void}".
Then an object can simply contain a reference to an instance of "SomeEventHandler", which won't give us any trouble when serializing. This will totally work well, but it's a little heavy handled, as I have to declare a new interface for every function handler that I want to serialize. Also, the other limitation of this, is that some object, can only handle that event (act as delegate) in one particular way. He can't be handle two separate handleThing events in two separate ways, because he can only implement that handler interface once.

Are there other serialization libraries that will do this easily?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Serializing objects that have references to functions (anyone know how)?

Jordo Odroj
Does anyone have any input on this?

On Sat, Feb 26, 2011 at 7:23 PM, Jordo Odroj <[hidden email]> wrote:
Hi Haxers,

I ran into a problem when serializing an object that had a reference to a function pointer. I understand the limitation. The function's true behavior is not only the code, but the data environment packaged into a closure. In my case, I knew that the function was not using any data in the closure but rather I had the following two situations:
1. The function was a method of an object:
2. In another situation, the function was just a helper handler (think static function of some helper class).

It seems like in both of these situations, it is, in fact practical to serialize the functions. In the case of one, we'd be serializing "the object the method is attached to" + "information about what method to invoke". In other words (as I've known for some time), Objects are really just very organized closures, we can serialize objects, why can't we serialize references to members that depend on their existence?
I could understand the difficulty in serializing arbitrary closures, but the object method case seems much more attainable, as the closures are well-known (they are only limited to the object (IIRC in haxe)).

For all the NON-Object methods, I could see being required to mark certain methods with @non-closure. Wouldn't this help many performance concerns? Would this just be equivalent with "inline"? 

The way I got around the problem for now, is by using the delegate pattern, common in Cocoal/OSX development. You simply define an interface "interface SomeEventHandler { function handleThing() : Void}".
Then an object can simply contain a reference to an instance of "SomeEventHandler", which won't give us any trouble when serializing. This will totally work well, but it's a little heavy handled, as I have to declare a new interface for every function handler that I want to serialize. Also, the other limitation of this, is that some object, can only handle that event (act as delegate) in one particular way. He can't be handle two separate handleThing events in two separate ways, because he can only implement that handler interface once.

Are there other serialization libraries that will do this easily?


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Serializing objects that have references to functions (anyone know how)?

Niel Drummond-3
I can't comment particularly on your topic, except to say the haxe serialization works OK for smaller object trees, though even with caching, you end up with large payloads that are quick to unserialize, but slow to serialize. I doubt serializing method code is going to help this.

Having said this, I know Russell did some work to alleviate this, I haven't done a comparison though:

http://code.google.com/p/caffeine-hx/source/browse/trunk/ext3/chx/Serializer.hx

- Niel

On 03/02/11 08:53, Jordo Odroj wrote:
Does anyone have any input on this?

On Sat, Feb 26, 2011 at 7:23 PM, Jordo Odroj <[hidden email]> wrote:
Hi Haxers,

I ran into a problem when serializing an object that had a reference to a function pointer. I understand the limitation. The function's true behavior is not only the code, but the data environment packaged into a closure. In my case, I knew that the function was not using any data in the closure but rather I had the following two situations:
1. The function was a method of an object:
2. In another situation, the function was just a helper handler (think static function of some helper class).

It seems like in both of these situations, it is, in fact practical to serialize the functions. In the case of one, we'd be serializing "the object the method is attached to" + "information about what method to invoke". In other words (as I've known for some time), Objects are really just very organized closures, we can serialize objects, why can't we serialize references to members that depend on their existence?
I could understand the difficulty in serializing arbitrary closures, but the object method case seems much more attainable, as the closures are well-known (they are only limited to the object (IIRC in haxe)).

For all the NON-Object methods, I could see being required to mark certain methods with @non-closure. Wouldn't this help many performance concerns? Would this just be equivalent with "inline"? 

The way I got around the problem for now, is by using the delegate pattern, common in Cocoal/OSX development. You simply define an interface "interface SomeEventHandler { function handleThing() : Void}".
Then an object can simply contain a reference to an instance of "SomeEventHandler", which won't give us any trouble when serializing. This will totally work well, but it's a little heavy handled, as I have to declare a new interface for every function handler that I want to serialize. Also, the other limitation of this, is that some object, can only handle that event (act as delegate) in one particular way. He can't be handle two separate handleThing events in two separate ways, because he can only implement that handler interface once.

Are there other serialization libraries that will do this easily?



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Serializing objects that have references to functions (anyone know how)?

David Elahee
In reply to this post by Jordo Odroj
Hi Jordo,

How do you solve the "remoting that can deserialize a function thus needing a compiler because he don't forcibly know the delegates code" problem ?

Cheers,
David.

Le 2 mars 2011 08:53, Jordo Odroj <[hidden email]> a écrit :

> Does anyone have any input on this?
>
> On Sat, Feb 26, 2011 at 7:23 PM, Jordo Odroj [hidden email]> wrote:
>
> Hi Haxers,
>
> I ran into a problem when serializing an object that had a reference to a function pointer. I understand the limitation. The function's true behavior is not only the code, but the data environment packaged into a closure. In my case, I knew that the function was not using any data in the closure but rather I had the following two situations:
>
>
> 1. The function was a method of an object:
> 2. In another situation, the function was just a helper handler (think static function of some helper class).
>
>
> It seems like in both of these situations, it is, in fact practical to serialize the functions. In the case of one, we'd be serializing "the object the method is attached to" + "information about what method to invoke". In other words (as I've known for some time), Objects are really just very organized closures, we can serialize objects, why can't we serialize references to members that depend on their existence?
>
>
> I could understand the difficulty in serializing arbitrary closures, but the object method case seems much more attainable, as the closures are well-known (they are only limited to the object (IIRC in haxe)).
>
>
>
>
> For all the NON-Object methods, I could see being required to mark certain methods with @non-closure. Wouldn't this help many performance concerns? Would this just be equivalent with "inline"? 
>
>
>
>
> The way I got around the problem for now, is by using the delegate pattern, common in Cocoal/OSX development. You simply define an interface "interface SomeEventHandler { function handleThing() : Void}".
>
>
> Then an object can simply contain a reference to an instance of "SomeEventHandler", which won't give us any trouble when serializing. This will totally work well, but it's a little heavy handled, as I have to declare a new interface for every function handler that I want to serialize. Also, the other limitation of this, is that some object, can only handle that event (act as delegate) in one particular way. He can't be handle two separate handleThing events in two separate ways, because he can only implement that handler interface once.
>
>
>
>
> Are there other serialization libraries that will do this easily?
>
>
>
>
>
--
haXe - an open source web programming language
http://haxe.org