[MLton] better support for C pointers
Anoq of the Sun
Mon, 01 Dec 2003 13:15:12 +0200
Stephen Weeks wrote:
> 1. Phantom typed pointers that can be used in _import.
> 2. Pointer arithmetic.
> 3. Memory fetch and store for various primitive types.
> val getInt: 'a t -> int
> val getWord: 'a t -> word
> val setInt: 'a t * int -> unit
> val setWord: 'a t * word -> unit
This would also be a _very_ welcome feature for me. For instance
for things like writing pixels to a framebuffer as I do
now using my own C-functions.
More ideas would be:
setInt32, getInt32, setWord32, getWord32 etc. since one
will often depend on the data size when integrating with C-code.
A malloc / free interface? Using ML-types maybe?
allocBytes : int -> 'a t
allocArray : int * 'a -> 'a t
The idea being that allocBytes allocates a particular amount of
bytes where as allocArray would allocate what corresponds to
entries * sizeof('a).
If done really cleverly - maybe the same alloc function could be
used and allocate with sizeof('a) when there is an explicit
type constraint on 'a and allocate bytes when 'a is not instantiated.
(but maybe allocating for boxing of 'a types would be more
correct or less confusing in that case?)
Anyway - just loose ideas :)