flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 13 Dec 2011, 08:58
There are two problems with using the stack for heap space.
1) Your stack size is limited at thread startup. You can't arbitrarily expand it at will later. 2) You need to touch the stack in 4kB intervals to trigger the page guard so the OS will commit memory. As long as you understand those things then you can use the stack for heap space. |
|||
![]() |
|
Overflowz 13 Dec 2011, 09:15
You don't understand me, I meant, how to manually do something like this API calls:
Code: VirtualAlloc/Ex, malloc, etc.. |
|||
![]() |
|
JohnFound 13 Dec 2011, 09:17
Using stack as a variables memory is common practice. But there is a one big disadvantage - you can't free and resize the memory other way than LIFO. If you defined A, B, C, D, then you can resize/free only D. If you want to resize B, then you must free D and C, resize B and allocate C and D again.
Also, these variables can be only local and they can be changed only on the same nesting level where they have been defined. The big advantage is that there is no fragmentation in the heap. |
|||
![]() |
|
revolution 13 Dec 2011, 09:18
Overflowz wrote: You don't understand me, I meant, how to manually do something like this API calls: |
|||
![]() |
|
Overflowz 13 Dec 2011, 09:19
I get it, thank you guys
![]() |
|||
![]() |
|
AsmGuru62 13 Dec 2011, 18:03
I just want to add that 'n' cannot be a random number - it must be a number divisible by 4 (a size of a DWORD). Some Win API may fail if you call them with mis-aligned ESP.
Also, 4Kb pages remark is applied if stack is not commited. In FASM, you can add a line at the top of source (after PE GUI 4.0 declaration): Code: stack 100000h,100000h It will reserve AND commit stack space for 1Mb, so you can allocate more than a page of room if needed. |
|||
![]() |
|
Overflowz 13 Dec 2011, 19:02
Is there any API call to reserve more stack size ? on runtime I mean.
|
|||
![]() |
|
revolution 13 Dec 2011, 19:11
Overflowz wrote: Is there any API call to reserve more stack size ? on runtime I mean. Above, I wrote: 1) Your stack size is limited at thread startup. You can't arbitrarily expand it at will later. |
|||
![]() |
|
AsmGuru62 13 Dec 2011, 19:30
A good question may be is: "why so much stack is needed?" - which will indicate a code design issue(s). I have built significant programs in FASM (my OOP IDE as an example) and I never needed more than 32Kb of stack and even that was a lot.
|
|||
![]() |
|
Overflowz 14 Dec 2011, 08:07
I was thinking to use stack instead of heap.. Just I'm curious, nothing else.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.