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;

Reply via email to