[gambit-list] How access arbitrary memory addresses (r/w)?
Mikael
mikael.rcv at gmail.com
Thu Aug 9 15:30:08 EDT 2012
Dear Marc,
Here is something that is really key for some lowlevel things: I wish to do
the equivalent of the C expression * ((byte*) x) in the Scheme world, i.e.
the same as something like MOV AL,[EAX] .
So, something like the C variant:
for (int i = 12345; i < 12445; i++)
print("%i ",* ((byte*) i));
would, if we call the read operator ##sysmem-byteref , be expressed
in Scheme as something like:
(let loop ((i 12345))
(if (< i 12445)
(begin
(print (##sysmem-byteref i) " ")
(loop (##fxnum+ i 1)))))
We can call the write operator ##sysmem-byte-set! . Also it would be of
great benefit to have one for 16bit, one for 32bit, one for 48bit and one
for 64bit words.
I think it's justified that there is some way to reach this with highest
efficiency, i.e. a way that does this inlined in the code thus producing
something like * ((byte*) x) / MOV AL,[EAX] .
Indeed this would provide of good efficiency on 64bit machines only, where
fixnums can go up to ~10^18 (unlike 32bit machines where it's ~0.5 * 10^9,
so pointers would generally be bignums).
Is this in place already, if not how is it best implemented? (with
##c-codeand some magick around it perhaps; I'd suppose with
##c-lambda there's always some handling around that would make it clearly
more than a single-cpu-instruction operation, even if compiled with (declare
(not safe)) ).
I may not be correct about this one but I got the impression that
##u8vector-ref/set! would *not* work for this, though perhaps a u8vector
object could be produced that is immovable and has zero as its offset
memory address?
Thanks,
Mikael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20120809/6bc59cac/attachment.htm>
More information about the Gambit-list
mailing list