proc genArray(i, j: int) : seq[cstring] =
      result = newSeqOfCap[cstring](j - i + 1)
      for k in i .. j:
        result.add(($k).cstring)
    
    var a = genArray(1, 900)
    
    for i in a:
      echo i
    

The output contains mostly valid numbers, but some garbage. Of course cstrings 
exists only for C FFI, so using it this way is really stupid. I tried it just 
for a test of a robin hood hash, to investigate how key size degrades 
performance. (I was a bit surprised at first that hash is much slower for Nim 
strings as key than for plain ints -- but it is clear, int size is 4 or 8 byte, 
Nim string size should be at least twice, c pointer and size.) For the code 
above -- may GC just free the string immediately?

Reply via email to