Version française
Home     About     Download     Resources     Contact us    
Browse thread
Efficency of varient types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <Alain.Frisch@i...>
Subject: Re: [Caml-list] Obj or not Obj
Christophe Raffalli wrote:
> - using Obj requires the same knowledge as writing C interface ...

It requires more knowledge: you must know how GC roots in the stack are
detected in native code. In this respect, (Obj.magic 0) and (Obj.magic
()) are not the same, contrary to what you might believe if you only
know how to write a C interface. (Obj.magic 0) makes the code generator
believe that the result can only be an integer; it will thus not traced
by the GC. Now, the same happens for the result of an expression like
(if ... then Obj.magic 0 else ...) because the compiler knows, thanks to
the type system, that if the then branch is an integer, then so is the
else branch. You can imagine the consequences. (I've made this mistake -
good thing Xavier was not too far.)

-- Alain