On Thursday, 26 May 2016 at 12:33:31 UTC, Adam D. Ruppe wrote:
On Thursday, 26 May 2016 at 12:30:30 UTC, Alex Parrill wrote:
The line "not having to make another array to keep track of
lengths and then shorten them" is fairly vague. "Shortening"
an array via slicing is basically free (it's just some integer
arithmetic), but I'm not sure if that's what you meant.
Indeed, creating a slice from a static array, another slice, or
a pointer is free too...
But managing the lengths separately and then re-slicing it
afterwards is not free. It does have a low constant cost though;
but can I remove that cost entirely (including the foreach loop
overhead)?
There's also the annoyance that on windows machines the stack
size seems to be fairly small. Sometimes in my tests the program
will crash before it starts because the requested size of a
static array on the stack is too big. This means if I have a big
stack allocation already, I want to try and avoid further
allocations if I can avoid it.
byte[1024*1024] buffer; //on my machine, it just crashes when
this is allocated.