The function _alloca (alloca) allocates memory on the stack, which does not require "free".
Is it possible to write a function that allocates on the stack in C?
Another way of phrasing it: _alloca does it!
Or is this not possible in C for other reasons including: 1) The functionality is written in ASM 2) It is a characteristic of the C run-time library.
The reason I am interested in writing an alloca-like function goes like this:
void func (const char *path, const char* filename)
{
char s[1024];
snprintf (s, sizeof(s), "%s/%s", path, filename);
}
But I would prefer:
void func (const char *path, const char* filename)
{
char *s = alloca_sprintf ("%s/%s", path, filename);
// ... No need to free.
}
Thanks in advance to anyone knowledgeable in this subject. asnprintf is an improvement over using a fixed-size buffer, but still requires clean-up.