What constitutes ‘small’ may also vary within a single
program. Something deeply recursive is completely different from a
non-recursive top-level procedure, for instance.
When I used 1024 as a “small” number, I did have some justification
in my mind.
I think that President Lincoln said once that two things that are equal
should be treated equally. Maybe he didn’t 
In my mind, calling alloca is like making a function call. If we must
tolerate function calls, then alloca should be tolerated as well. Now
the real question is what the average size of a function frame is.
My thought was that having a hundred variables of word-size should
be enough.
So 100 * 8 bytes = 800 bytes. Rounding it up to the next power of 2
gives you 1024.
I am not against alloca(1024) but I am against alloca(1024*1024) :)On Friday, October 31, 2014 8:26:24 PM UTC-4, Barry Schwartz wrote:
gmhwxi <gmh...@gmail.com <javascript:>> skribis:
Here is my rationale not supporting it:
- To me, it is always safer to malloc
if [n] is unknown at compile-time unless…
Well, yeah, but I think I can come up with serious
counterarguments. For instance, people who write libraries should not
be deciding for the library’s user what constitutes a ‘small’ array;
they should simply be providing something to handle the case, if they
are inclined to do so.
What constitutes ‘small’ may also vary within a single
program. Something deeply recursive is completely different from a
non-recursive top-level procedure, for instance.
Finally, there are types of programming where one does not want
ordinary buffer overruns, dangling pointers, mallocs without free,
etc. – basically where a person wants to be helped avoid common
programming errors – but frankly doesn’t care much if the stack in
very remote instances might be exceeded, causing a segfault. I’m
thinking for instance of my Sorts Mill Tools, where my goal in perhaps
using ATS would be to slowly undo the extreme bugginess and
intractability of the C code I inherited from FontForge, but where I
don’t really care if it uses more stack than some person somewhere can
provide. I don’t even care about the buffer overruns and dangling
pointers, except that they represent actual bugs in the algorithms.