Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: fancy GC question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien Doligez <Damien.Doligez@i...>
Subject: Re: fancy GC question
>From: Markus Mottl <mottl@miss.wu-wien.ac.at>

>When I allocate an integer array in OCaml, which is always boxed, both
>the pointers to and the elements are obviously contiguous in memory.

There's no pointer in an integer array.


>  int *ar = (int *) &Field(v_ar, 0);

>But is this really always safe if only C writes to the array? What about
>e.g. heap compactions and other GC-actions? Can other effects mess up the
>fact that the pointers map continuously on a contiguous chunk of memory
>(of integers)?

Heap compaction can move the array and break your code (unless you
make sure to reset your ar variable after each compaction).  Future
versions of the GC may move the array under other circumstances.  And
if your array is small enough and was allocated in the minor heap,
then the minor GC will move it too.

>If yes, this would, of course, require the traditional use of the
>"Field"-macro for every access. Otherwise, one could squeeze out a bit
>more performance in some (probably rare) cases.

Make sure you really need that performance and understand the
maintenance cost before using such tricks.

-- Damien