On Mon, 09 Jan 2012 08:33:18 +0100 Gerd Stolpmann <[email protected]> wrote:
> If you are looking for more optimizations, you can also replace the > first Store_field with Field(newblock,0) = Val_int(h). Store_field is > slightly more expensive, because there is a test whether you create a > pointer from the old generation to the young generation, which is only > allowed if this pointer is added to a special list. You only assign an > int here, so it cannot be a pointer. > > For the second assignment you need Store_field because there is no > (official) guarantee that newblock is created in the young generation > (although I don't see a reason why newblock could ever reside in the old > generation, but it's really dependent on implementation details in the > GC). AFAIK the better (and described in manual) way is to use caml_alloc_small and direct assignment into fields in this case. To answer OP's question: CAML* macros are used to live in harmony with GC, and GC manages ocaml heap. So one should always use these macros when (and by the same rules) the code touches values in ocaml heap - no matter whether the function is called directly from ocaml side or not. -- ygrek http://ygrek.org.ua -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
