I know that the behavior ot _alloca is to release the memory off the stack when you leave the function. Is there a way to release the memory earlier?
Asked
Active
Viewed 412 times
0
-
@Mysticial: `_alloca` is constrained by the size of stack — usually no more than a megabyte. Ill-advised as it is, I can readily understand the desire to reuse such a scarce commodity. – Marcelo Cantos Sep 26 '12 at 10:02
-
2No, and also, don't use `_alloca`. – Kerrek SB Sep 26 '12 at 10:03
-
1If your compiler supports VLAs (from C99) as an extension, then a block-scoped VLA will release when the block is exited rather than when the function is exited. – Steve Jessop Sep 26 '12 at 10:03
2 Answers
2
Nope. There's no point in using _alloca
anyway- you can write a high-speed pool memory allocator that can allocate and deallocate faster from the heap, and with less size restrictions.

Puppy
- 144,682
- 38
- 256
- 465
1
no there isn't (excluding messing with stack explicitly, e.g. in an asm
block) but you can use _malloca
and _freea
, if you need something like that.
EDIT: as BoBTFish notes: If it was allocated on the stack, _freea does nothing
so this answer is incorrect wrt releasing the memory earlier. However, I think it is better not to delete it as it points to an alternative to _alloca
which is somewhat safer.

Zdeslav Vojkovic
- 14,391
- 32
- 45
-
The _freea function deallocates a memory block (memblock) that was previously allocated by a call to _malloca. _freea checks to see if the memory was allocated on the heap or the stack. *If it was allocated on the stack, _freea does nothing.* – BoBTFish Sep 26 '12 at 10:33