I think that question has been answered many times already, and I am nearly 
sure you know it already. At least you are no newbie, I have seen you name in 
this forum for at least a few months already :-)

Nim array is basically a C array located on the stack, so just a fixed block of 
memory. As it is located on the stack there is no alloc/dealloc needed, 
allocation is just increasing the stack pointer. Dont't ask me how returning a 
array from a proc works exactly, but I assume it works also without 
alloc/dealloc.

seq and string is basically an object, at least one length field and a pointer 
to payload, that is the real data content. Content is dynamically allocated and 
deallocated. When data elements are added, data buffer may get exhausted, then 
a new payload buffer is allocated and data is copied there. There may be 
exceptions, as when area after buffer is still unused, OS may allow increasing 
a buffer already in use, that operation may be called realloc() or something 
like that. seq and string works very similar to C++ std::vector. Details my 
vary for Nim V2, newruntime, arc memory management and all that what may come.

Note, C may allow dynamically sized arrays living on stack. That can work for 
special cases, as stack pointer can be increased dynamically at runtime. There 
exists a forum post to this behaviour.

And finally there is openArray, basically a container for passing array or seq 
to procs, so I assume it is a length field and a pointer to payload.

Reply via email to