I am trying to read c-array into a sequence. If somebody could confirm if my understanding is correct.
In one hand, I have in C world: an address, the array size and the type. Something like: bufferptr, size and uint8 (it contains an image).
In order to load the buffer into the seq, is the following right?
var data = newSeq[uint8](size)
for i in 0..<size:
data[i] = cast[seq[uint8]](bufferptr)[i]
Another thing that I would like to understand is pointer airithmetic. Is the following right?
let address = cast[pointer]( cast[int](bufferptr) + offset )
let value = cast[uint8](address)
Is my understanding correct?
Alternative:
let mybuf: ptr uint8 = ...
let mybufLenInBytes: int = ...
var s = newSeq[uint8](mybufLenInBytes)
if mybufLenInBytes != 0:
copyMem(addr s[0], mybuf, mybufLenInBytes)