How can I implement a stack allocation method alloc()
using assembly in Delphi? It isn't even exported from msvcrt.dll
the way malloc/free
is.
Asked
Active
Viewed 402 times
0

user15124
- 299
- 3
- 8
-
`getmem` should work – Grim Oct 18 '15 at 11:06
-
@PeterRader that allocates on heap. – user15124 Oct 18 '15 at 11:26
-
For a start, details matter. The function is called `alloca`. Be precise. Get some ideas on how to do it from the code in Grids.pas, perhaps named StackAlloc IIRC, which I probably don't. It's dangerous to do this though. Easy to stomp on the compiler. Are you sure you need to do it. – David Heffernan Oct 18 '15 at 11:26
-
@DavidHeffernan Are you sure that's the same method as the one found in GCC, MSVC? The one in Delphi requires free. But the `alloca` doesn't. – user15124 Oct 18 '15 at 11:29
-
Am I sure that what is what? Again be precise. – David Heffernan Oct 18 '15 at 11:31
-
@DavidHeffernan These are not the same methods. `StackAlloc` in Delphi requires `StackFree` yet the `alloca()` in C++ doesn't. – user15124 Oct 18 '15 at 11:33
-
1I thought you wanted to allocate memory on the stack. Was I wrong? In any case, I think calling StackFree is optional. – David Heffernan Oct 18 '15 at 11:33
1 Answers
1
There is a functioning implementation of StackAlloc
in the graphics32 library. This supports x86 and x64 targets.
I learned this from a websearch which took me here: How to use StackAlloc in x64?
The other well known implementation that I am aware of can be found in the Grids
unit of the VCL.

Community
- 1
- 1

David Heffernan
- 601,492
- 42
- 1,072
- 1,490