flat assembler
Message board for the users of flat assembler.
Index
> Windows > heap & stack |
Author |
|
RedGhost 18 Sep 2006, 21:28
The stack is local memory that is allocated per process, it is usually a fixed size (1mb or something?), when you do push/pop this is using the stack. In Windows there is a process heap and you can use the system memory (heap). The stack is generally faster because it's already allocated, but it's very limited to how much it can hold.
I am sure some one like Tomasz will come and expand on this . _________________ redghost.ca |
|||
18 Sep 2006, 21:28 |
|
vid 18 Sep 2006, 22:02
stack is thing that is used with "PUSH", "POP", "CALL"s return address, etc. It's a thing on which you can add dword sized things ("push" them), and then remove then is reversed order as you was adding them ("pop" them). ESP register is pointing to things that was last added to stack (it's called "top of stack). when you push something to stack, you do this:
1. subtract size of something from ESP 2. copy something to memory pointet by ESP and when you pop something from stack 1. copy something from memory pointet by ESP to where you want it 2. add size of something to ESP ... hope that clears things a little, altough i realize it's far from enough explaination. heap is just bunch of memory that is used with things like C's "alloc()", "realloc()", eg. dynamic memory handling. for example you say - now i need X bytes of memory. Value of X is not known during compilation (for example, it depends on user input). So you just call alloc with argument of X, and it allocates given amount of memory (from "heap"), and returns pointer to you. After you are done with memory, you call free and memory is "freed", you can no longer use it. This is implemented by allocating one big chunk of memory first, from which "alloc" takes how much it needs and "free" puts it backs. That chunk is called "heap" |
|||
18 Sep 2006, 22:02 |
|
eskizo 20 Sep 2006, 13:13
hi angain!
I don't want to create a new thread to ask up this: - Once the stack is a fixed memory block, can the program point static variables to stack begining (the last pointer used) to save fixed memory size ? - Is HeapAlloc better than Global/LocalAlloc ? I've seen somewhere that HeapAlloc is the fastest way to get a block of memory. thankyou all! |
|||
20 Sep 2006, 13:13 |
|
vid 20 Sep 2006, 13:24
first: why to do this? you can set stack smaller and data segment larger
second: don't care, use any of them |
|||
20 Sep 2006, 13:24 |
|
Goplat 20 Sep 2006, 16:31
HeapAlloc is the fastest heap allocator, since malloc/GlobalAlloc/LocalAlloc/etc are all just wrappers around it.
|
|||
20 Sep 2006, 16:31 |
|
eskizo 20 Sep 2006, 18:27
vid,
Quote:
first: Good answer, but I am not talking about DOS; It was just to know the possibility of doing what I sad... If necessary, I would set CODE section READABLE WRITEABLE to hope all my static variables; 2nd: alright |
|||
20 Sep 2006, 18:27 |
|
Reverend 20 Sep 2006, 19:49
Data segment = data section
|
|||
20 Sep 2006, 19:49 |
|
eskizo 20 Sep 2006, 20:03
lol
|
|||
20 Sep 2006, 20:03 |
|
RedGhost 21 Sep 2006, 04:04
If you want stack allocation with some kind of procedure there is alloca() from the CRT, it gets destroyed when a procedure leaves but I imagine you would need to manaully balance the stack before doing a 'ret' instruction.
_________________ redghost.ca Last edited by RedGhost on 23 Sep 2006, 05:02; edited 1 time in total |
|||
21 Sep 2006, 04:04 |
|
vid 21 Sep 2006, 06:45
if you use EBP-pointed stack, then you don't need to balance it:
Code: ;enter procedure push ebp mov ebp, esp sub esp, locals ;eax = alloca(100) sub esp, 100 mov eax, esp ;return mov esp, ebp pop ebp ret |
|||
21 Sep 2006, 06:45 |
|
Reverend 21 Sep 2006, 19:21
eskizo: What I meant is that when vid mentioned data segment, he wanted to say data section (as I understand it). You wrongly assumed he was talking about DOS.
|
|||
21 Sep 2006, 19:21 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.