A common idiom that is no longer as common is to always create a stack buffer up to a certain small bound and then an allocation if it goes beyond:
void dwim(unsigned count) {
struct Something _buffer[10];
struct Something* buffer;
if (count < sizeof(_buffer) / sizeof(_buffer[0]))
buffer = _buffer;
else {
buffer = (struct Something*) malloc(count * sizeof(struct Something));
}
doSomething(buffer, count);
if (buffer != _buffer)
free(buffer);
}
It used to be really common to write that without considering if it was a necessary optimization or not - nowadays I would just malloc up front.