[MLton-devel] Direct memory access / Memory mapping

Matthew Fluet Matthew Fluet <fluet@CS.Cornell.EDU>
Fri, 28 Jun 2002 09:12:16 -0400 (EDT)


> Is there a function/primitive in MLton which can be used to access memory 
> direclty by passing it the address? 
> 
> E.g.
> 
>   Memory.getChar : word32 -> char 
>   Memory.getWord32 : word32 -> word32

There's nothing like that currently in MLton, although it wouldn't be
terribly difficult to add.  You can access a statically named location
with a nullary _ffi, but I assume with the above you're looking for
dynamically being able to compute the word to examine.

Such primitives wouldn't be terribly difficult to add; and we've actually
had some requests for the corresponding setting of memory locations for
faster graphics manipulation.

> I need to memory-map a large file into memory (I can do this easily in a C-extension).  
> Then I would need another C-funtion that accesses the memory.
> But calling each time a C-function to access a single byte might be to much overhead, compared
> to a few inlined machine instructions.

The overhead of a C-call isn't really that much.  Manipulation of
primitive C-strings (for example, copying a null terminated C-string into
the heap) is mediated by
Char C_CS_sub(Cstring s, Int i) {
	return ((char*)(s))[i];
}

void C_CS_update(Cstring s, Int i, Char c) {
	((char*)(s))[i] = c;
}

At one point in time, I modified the backend to implement calls to these
functions with their corresponding machine instructions, but it had no
runtime affect at all.

-Matthew




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Caffeinated soap. No kidding.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel