Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Efficency in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jerome Vouillon <Jerome.Vouillon@i...>
Subject: Re: Efficency in OCaml
On Sat, Sep 04, 1999 at 05:26:33PM +0300, Nicolas Ollinger wrote:
> I played a little with objects representation in OCaml 2.xx. As far as
> I understand, at least in bytecode, class instances are represented as
> boxed values tagged object_tag with n+2 fields : then first field is the
> method array array described by Jerome in last mail, the second field
> seems to be a unique id associate to the object, other fields are used
> for instance variables in the order of declaration, inherited variables
> first. As the method array array is unique for each class, it can be used
> to identify the class (notice that classes are represented as global
> variables).

This is correct.

> I'm intrigued by this second field, what is the use of this
> id ? Where is the necessity to identify uniquely every object ?

This allows to compare objects using "(<)" or "compare" (and therefore
makes it easy to create sets of objects).

> Concerning marshaling of objects, a simple solution is to use a function
> like:
> 
> let crunch o =
>   let r = Obj.dup (Obj.repr o) in
>   let idclass = compute_id (Obj.field r 0) in
>   Obj.set_field r 1 idclass;
>   Obj.set_tag r Obj.marshaled_object_tag
>   r;;
> 
> with compute_id a function that deduce a unique class id of the object.
> 
> Then unmarshaling is just doing the inverse operation. Of course, if
> you want to share objects between different programs then you must add
> some information about the module in which the class is declared, and
> so one.

This would work. The hard part is to generate this information...

-- Jérôme