Using unsafe pointers have risks. Here is example wrong code:
    
    
    var
      s = @[1]
      pi = s[0].addr
    echo pi[]
    s.add 2
    s[0] = 100
    echo pi[]
    echo s[0]
    
    Run

I think using indices instead of pointers is safer and almost as fast as 
pointers. Pointer size is fixed (8bytes in 64bit CPU), but index can be 16 or 
32 bits int as long as a number of points is smaller than 2^16 or 2^32.

I recommend you to write simple and working code first. If you write unsafe 
code, you might spend a lot of time for debugging and give up the project 
before you write correctly working code. Correctly working code is much better 
than faster code that produces wrong result. When fast but unsafe code produced 
output that looks like correct, how do you know whether it is actually correct 
or not? It is not easy to write fastest code as modern CPU and compiler are 
complex. Sometimes, I tried to write fastest code but it was slow. Data 
structure that I thought slow was actually not so slow. 

Reply via email to