Well, just following that manual section and compiler messages, replace 
`memRegion` (a variable) in the last line with a type, the type you want to 
point to, `PinnedArray[int]` in your case, and to the left to that `ptr` put 
another object type, serving to distinguish your memory region, like: 
    
    
    type Cuda = object # nothing needed inside, serves just as a mark
    var foo: Cuda ptr PinnedArray[int] # read this as "Cuda-pointer to 
PinnedArray[int]"
    

> Nimsuggest also says "region needs to be an object type"

That's explicit in that manual section.

* * *

UPD

Something that compiles, though too much casts, and maybe not best fits your 
needs: 
    
    
    type
      UncheckedArray {.unchecked.}[T] = array[0..100_000_000, T]
      PinnedArray[T] = object
        len: int
        data: ptr UncheckedArray[T]
      Cuda = object
    
    var foo: Cuda ptr PinnedArray[int]
    foo = cast[ptr[Cuda, PinnedArray[int]]](alloc sizeOf(PinnedArray[int]))
    foo.data = cast[ptr UncheckedArray[int]](alloc 50_000)
    foo.len = 50_000
    
    foo.data[][2]=7
    echo foo.data[][2]
    

Reply via email to