caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* A pair of "Interfacing with C" questions
@ 2005-07-21  4:53 Robert Roessler
       [not found] ` <8210502975.20050721082753@moldavcable.com>
  2005-07-21 10:21 ` Jacques Garrigue
  0 siblings, 2 replies; 8+ messages in thread
From: Robert Roessler @ 2005-07-21  4:53 UTC (permalink / raw)
  To: Caml-list

1) in wrapping a large widget with multiple interfaces using 
"strings", I sometimes allow the widget to copy a C-string into a 
Caml-allocated string - INCLUDING "overwriting" the terminating zero 
byte with zero... I wanted to make sure this was not seen as a major 
problem.

As I understand the Caml runtime's use of strings (at least one zero 
byte always being present), this does not seem like a problem to me - 
and until memory protection granularity practices change a lot, there 
should not be any trouble there... :)

2) this is about "future-proofing" (at the source level) code which 
interfaces with external [foreign] components and needs to store and 
pass around "opaque pointers": what is the best base Caml data type to 
use?

I currently use

type opaque_ptr = int32

I assume the other choices include int64, nativeint, or even int.

int64 - good if you know you are dealing with 64-bit values, obviously 
not suitable in the general case.

nativeint - this looks promising, as long as you do not need to deal 
with a 64-bit-int/32-bit-pointer model... would it be safe to assume 
that in any 64-bit Caml implementation, ints/pointers/"values" will 
ALL be 64-bit?

int - there clearly is a restriction on using only pointers with the 
low bit set to zero; if you can stipulate that this is a non-issue, 
then you can just SET/CLEAR the low bit at the Caml/C boundary and 
then be able to safely store to and retrieve from Caml "value" fields 
(I think).

So... is the winner int or nativeint?  Or ?  And yes, I know that 
using int will avoid an extra allocation... but are there other 
considerations not represented here?

Any relevant insights will be appreciated. :)

Robert Roessler
roessler@rftp.com
http://www.rftp.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-07-23 12:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-21  4:53 A pair of "Interfacing with C" questions Robert Roessler
     [not found] ` <8210502975.20050721082753@moldavcable.com>
2005-07-21  5:44   ` [Caml-list] " Robert Roessler
2005-07-21 10:21 ` Jacques Garrigue
2005-07-21 10:29   ` malc
2005-07-21 11:51     ` Jacques Garrigue
2005-07-22  5:26       ` Robert Roessler
2005-07-22  9:31         ` Alexander S. Usov
2005-07-23 12:14     ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).