Allocating a wstring on the stack (no GC)?

monarch_dodra via Digitalmars-d digitalmars-d at puremagic.com
Wed May 7 15:31:45 PDT 2014


On Wednesday, 7 May 2014 at 19:18:09 UTC, Maxime 
Chevalier-Boisvert wrote:
>>> Is the slice going to be allocated on the stack? (I imagine 
>>> the answer is yes)
>>
>> Slicing doesn't change where the data is allocated. Slicing 
>> means just creating a new struct that contains a length and 
>> pointer to the data (and the struct itself is allocated 
>> in-place. So it's allocated on the stack, or inside a struct 
>> instance, or inside a class instance, or on the data segment, 
>> etc).
>
> Indeed. It's the struct representing the slice I was asking 
> about. Off to test out the performance impact :)

I slice is really nothing more than a fat pointer (a pointer + a 
size_t). You don't really allocate it any more than you allocate 
a pointer when you do:
int* p = &someInt;


More information about the Digitalmars-d mailing list