Allocating a wstring on the stack (no GC)?

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 01:40:37 PDT 2014


On Wednesday, 7 May 2014 at 18:34:10 UTC, Meta wrote:
> On Wednesday, 7 May 2014 at 18:29:23 UTC, Brad Anderson wrote:
>> Unless I'm misunderstanding it should be as simple as:
>>
>> wchar[100] stackws; // alloca() if you need it to be 
>> dynamically sized.
>>
>> A slice of this static array behaves just like a slice of a 
>> dynamic array.
>
> But you should avoid slicing the static array unless it's via 
> arr.dup.

I use slicing of fixed size arrays a lot.

Sure, you have to keep track of the memory to make sure it 
doesn't survive past the current scope (or at least isn't used 
past that point, depending on how security critical your 
application is), but that's often trivial to do and saving the 
extra allocation can make a big difference to performance.


More information about the Digitalmars-d mailing list