Nim
Nim copied to clipboard
Document Nim data structure layout
It would be really nice if somebody could write some documentation explaining the layout of Seq[T] and other data structures in Nim.
Memory layout?
Yep.
@dom96 can you be a bit more specific what exactly would be a task here? (a short example would be great)
The task is to document what seq
and other common types actually look like in memory:
A sequence type is really just an object containing two fields: the length and a pointer to the first element.
type Seq[T] = ref object len: int data: pointer
I've made that up, I can't remember exactly what the structure of a seq looks like and I'm too lazy to look it up. But hopefully you get the idea :)
http://zevv.nl/nim-memory/#_how_nim_stores_data_in_memory was my first intro, and is great, but needs updating for seq and string v2
maybe also:
- UncheckedArray
- openArray
- some discussion of the RTTI pointer
I am really looking forward to it. The documentation @shirleyquirk has written is a great beginning, but I would like to understand more the internals.
Maybe we can add urls to specific parts of the std lib mentioned by the doc. I am thinking of the seq implementation :
This data is normally hidden from the user, but you can simply find the implementation of this header in the Nim system library, and it looks like this:
type TGenericSeq = object
len: int
reserved: int
I have been surprised to learn with similar examples as those given in this documentation, that adding to an object the mention of RootObj
requires an extra slot in memory (which is important to know for embedded development I guess ?).
There is http://zevv.nl/nim-memory/#_how_nim_stores_data_in_memory and feel free to write an article about it.