[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Garrigue <garrigue@m...> |
| Subject: | Re: [Caml-list] C interface style question |
From: Thomas Fischbacher <Thomas.Fischbacher@Physik.Uni-Muenchen.DE> > value-type parameters to C functions exported to OCaml should be > registered with CAMLparamX(...). Does this hold in general, or is it > considered acceptable/appropriate to just ignore this for "immediate" > values that do not hold pointers, but, say, int, bool etc. values? Registration is required to have the GC properly update the values. The GC may be called by any allocation. So it is only safe not to register a parameter (or a variable) in any of the following 4 cases. 1) you know that it can only hold a non-pointer value (int, bool, ...) (i.e. the GC has nothing to update) 2) there are no allocations in your function 3) the parameter is not accessed after the first allocation 4) for a new variable whose contents is returned, there is no allocation between the setting of the variable and return. (1) and (2) are relatively easy to see, but (3) and (4) are a bit trickier (particularly with side-effecting expressions), so it is not a bad idea to register more parameters than strictly necessary. Jacques