Skip to content

Instantly share code, notes, and snippets.

@kcrimson
Created November 18, 2015 23:42
Show Gist options
  • Save kcrimson/75f1cdd5cc590695adcb to your computer and use it in GitHub Desktop.
Save kcrimson/75f1cdd5cc590695adcb to your computer and use it in GitHub Desktop.
how to map files into memory in pony
use "files"
use "collections"
use @mmap[Pointer[U8]](addr : Pointer[U8], length : U64, prot : I32, flags : I32, fd : I32, off_t : I64)
use @open[I32](name : Pointer[U8] tag,flags :U16)
use @close[I32](fd : I32)
actor Main
new create(env : Env) =>
let fd : I32 = @open("file".cstring(),2)
let p = @mmap(Pointer[U8].create(),1024,2,1,fd,0)
if p.is_null() then
env.out.print("failed to map memory")
end
let arr = Array[U8].from_cstring(p,1024,1024)
try
arr.update(0,16)
end
env.out.print("it works")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment