3 ms·
> touch a byte every 4KB in the direction of stack growth before you use bulky stack allocations I don’t think you can portably (1) do that. You have to alloca
by Someone 5y ago
> touch a byte every 4KB in the direction of stack growth before you use bulky stack allocations
I don’t think you can portably (1) do that. You have to allocate before you can touch those bytes.
Also, if you do before, I don’t think there’s a guarantee that you won’t hit some volatile memory that interacts with hardware, and of course, there’s no portable way to get the stack pointer, in the first place (if only because it, conceptually, doesn’t exist in C)
(1) specific compilers can safely do that because they know how they are implemented, and many compilers are fairly similar, so one can make this “quite portable”, but not really portable.
- cryptonector 5y agoOne way is to allocate first. alloca(1GB) typically isn't going to cause a SEGV, so you can check the allocation after making it. With VLAs you have to make sure (this is not portable) that the compiler will put your loop iterator state variables ahead of the VLA. If you can assume a linear stack (which is kinda the whole point of this discussion) then you can call a function that will repeatedly alloca() in small chunks and touch a byte and return on success or SEGV on failure, and then when it returns it will release that memory but then you know you can safely alloca() that much.