More on C++ stack arrays
Denis Shelomovskij
verylonglogin.reg at gmail.com
Mon Oct 21 08:26:24 PDT 2013
21.10.2013 18:04, dennis luehring пишет:
> "...Implementation note:
> For small strings tempCString will use stack allocated buffer, for
> large strings (approximately 1000 characters and more) it will allocate
> temporary one from unstd.memory.allocation.threadHeap..."
>
> does that mean that tempCString reserves minimum 1000 bytes on stack
> else using heap?
>
> if so i would prefer a template based version where i can put in the size
Yes, `tempCString` allocates `1024 * To.sizeof` bytes on the stack. Note
that it doesn't initialize the data so it is O(1) operation which will
just do ~1 KiB move of stack pointer. As function stack frame can easily
eat 50-100 bytes it is like 10-20 function calls. IIRC typical stack
size is ~1 MiB and `tempCString` isn't expected to be used in some deep
recursion or be ~1000 times used in one function.
So I'd prefer to change default stack allocation size if needed and not
confuse user with manual choice.
--
Денис В. Шеломовский
Denis V. Shelomovskij
More information about the Digitalmars-d
mailing list