I just did some testing and the time doesn’t really increase if one adds 20 fields of Doubles, CString, Ptr, etc. to a one-field-structure.
When I compare it to a class with one property, the time increases drastically when I add the same 20 properties to it.
My interpretation is:
Structure: memory “allocation” by the compiler = very fast
Class: memory allocation at runtime = slow
- Is it safe to assume that structures always are on the stack, and that even large ones are not allocated on the heap?
- Can one run out of stack space?
Not sure the relavance of your question.
Where and how XOJO stores data should be of little importance to the developer (in most cases)
And #2… yes very easy to run out of stack space… just try thig
All data (class, structures, etc) take up memory.
Structures suffer from one major shortfall… Strings cannot be defined with a dynamic length (must be Cstring? PString?) where in a Class they can be …
It’s not a guarantee the language provides, but it’s true right now and I don’t see it changing anytime soon.
It’s slightly worse than this. Strings in structures don’t have encoding information associated with them, so if you’re treating it as textual information you’ll have to call ConvertEncoding when you put the data in and DefineEncoding when you pull it out.