You can probably use `cstring` if on a C backend, but if you wanted to index 
some other element type than `char` (like `int` or `Foo`) you can also do 
    
    
    let foos = cast[ptr UncheckedArray[Foo]](mmaped_file.mem)
    if i * Foo.sizeof < mmapped_file.size:
      doSomethingWith foos[i]  # e.g. i == 0 for 1st Foo
    
    
    Run

You may well be able to skip the range check every time if you are, e.g. 
looping over the file & know you won't overflow from that, etc. To recover 
automatic bounds checks, you can write new/use existing procs accepting 
`openArray[Foo]` (e.g. `openArray[T]`) and pass via `toOpenArray` explicitly in 
the parameter list: 
    
    
    fun(toOpenArray(mf.mem, 0, mf.size div Foo.size - 1), a, b, c)
    
    
    Run

That can be abbreviated with a `template oaFoo(mf)` if you need to pass it or 
various files in several places or something. If such procs want to modify the 
data the file needs to have been opened writable or you will get segmentation 
violations.

Reply via email to