I would suggest that you don't actually want an ML integer type to hold your C pointers. The main reason is that you would lose some type-safety because type checking would not detect accidental use of an integer as a pointer (and vice-versa).

What you should want in ML is an abstract type for a pointer, say, Pointer.t that has the required operations. Creating a simple signature/structure to provide a pointer type (defined internally as a vol) would go some way to removing the confusion about using vol directly.

In ML, the types SysWord.word and IntInf.int would be wide enough to hold pointer types. With Poly/ML, I'm sure it would be much more efficient to use a vol. (On my x86_64 system, SysWord.wordSize = 126.) Also, if you're going to use the garbage collector to free memory when a pointer is no longer referenced, your pointer types must be based on a vol.

Phil

26/09/14 09:59, [email protected] wrote:
Hello.

As I can see, there is no address type. The suggested conversion for C
pointers (POINTER : vol Conversion) converts a C pointer to "vol".

As follows from
http://www.polyml.org/docs/CInterface.html#17%20Volatile%20Implementation
, "vol" contains an address of a heap object. If its boolean field
"owns" is true, it garbage-collects its heap object.

If a C library requires that freeing a heap object be done explicitely,
managing an address to that heap object by "vol" is inefficient and
confusing. A "vol" value contains an index of the element of the "vols"
array which contains an address of a memory block which contains an
address of the heap object. What I really need is an ML integer type
that is wide enough to hold a C pointer; I called it "address type".

I'm trying to create a binding to the XCB library (
http://xcb.freedesktop.org/ ). Some functions from XCB don't manage
memory (so the Poly/ML garbage collector may be used); some functions
are allocating objects, and those objects must be freed by the function
"free" or "xcb_disconnect".
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml



_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to