@OderWat: do you mean something like this?
    
    
    proc shift[T](a: var openarray[T]; d: int) =
      if d == 0: discard # do nothing
      elif abs(d) >= a.len: # reset all
        zeroMem(addr a[0], a.len*sizeof(T))
      elif d > 0: # right shift
        moveMem(addr a[d], addr a[0], (a.len - d)*sizeof(T))
        zeroMem(addr a[0], d*sizeof(T))
      elif d < 0: # left shift
        moveMem(addr a[0], addr a[-d], (a.len + d)*sizeof(T))
        zeroMem(addr a[^(-d)], -d*sizeof(T))
    

But as Stefan said, I'm not sure how the gc sees this ( I think it's fine, as 
the total amount of memory doesn't change ( right? ) , we just change its value 
)

ps: what's a good way to benchmark this ( on windows ) ?

Edit: thinking about it, I'm not sure what would happen to refs that get moved

Reply via email to