flat assembler
Message board for the users of flat assembler.
Index
> Windows > VirtualAlloc trouble Goto page 1, 2, 3 Next |
Author |
|
revolution 20 Dec 2009, 11:04
the problem is here:
Code: @@: mov [stA+ecx*4], 'abcd' ... @@: mov [stA+ecx*4], 'abcd' Perhaps you meant: Code: @@: mov [eax+ecx*4], 'abcd' ... @@: mov [eax+ecx*4], 'abcd' invoke VirtualFree,[stA],8192,MEM_RELEASE ; <-- also it's not releasing |
|||
20 Dec 2009, 11:04 |
|
Teehee 20 Dec 2009, 11:13
Quote: Your stA buffer is too small But I alloc 8192 bytes... It still doesn't working... |
|||
20 Dec 2009, 11:13 |
|
revolution 20 Dec 2009, 11:14
No, you allocate just 4 bytes.
The 8192 byte allocation is never used in your original code. |
|||
20 Dec 2009, 11:14 |
|
revolution 20 Dec 2009, 11:17
Also check the documentation for VirtualFree:
Quote: If the dwFreeType parameter includes the MEM_RELEASE flag, this parameter (dwSize) must be zero. Code: invoke VirtualFree,[stA],0,MEM_RELEASE |
|||
20 Dec 2009, 11:17 |
|
Teehee 20 Dec 2009, 11:18
So how can I use the 8192 bytes? _________________ Sorry if bad english. |
|||
20 Dec 2009, 11:18 |
|
revolution 20 Dec 2009, 11:18
Teehee wrote:
|
|||
20 Dec 2009, 11:18 |
|
Teehee 20 Dec 2009, 11:21
but and this line:
Code: mov [stA], eax ? stA doenst points to eax? |
|||
20 Dec 2009, 11:21 |
|
revolution 20 Dec 2009, 11:22
But then you overwrite it with this:
Code: @@: mov [stA+ecx*4], 'abcd' |
|||
20 Dec 2009, 11:22 |
|
Teehee 20 Dec 2009, 11:27
oh.. you right! thanks now it works
|
|||
20 Dec 2009, 11:27 |
|
Teehee 20 Dec 2009, 11:41
here:
Code: invoke VirtualAlloc,0,8000,MEM_COMMIT,PAGE_READWRITE mov [stA], eax mov ecx, 0 @@: mov [eax+ecx], byte 'a' inc ecx cmp ecx,8191 jne @b mov [eax+ecx], dword 0 invoke MessageBox,NULL,[stA],NULL,MB_OK invoke VirtualFree,[stA],0,MEM_RELEASE I alloced 8000 bytes, but I can go till 8191 bytes. Why? |
|||
20 Dec 2009, 11:41 |
|
revolution 20 Dec 2009, 11:43
Teehee wrote: I alloced 8000 bytes, but I can go till 8191 bytes. Why? |
|||
20 Dec 2009, 11:43 |
|
Teehee 20 Dec 2009, 11:43
bc I need to alloc pow 2 space?
|
|||
20 Dec 2009, 11:43 |
|
Teehee 20 Dec 2009, 11:44
ohh ok
|
|||
20 Dec 2009, 11:44 |
|
revolution 20 Dec 2009, 11:45
It is related to the hardware paging in the CPU. You can't page less than 4k in the x86 CPU.
|
|||
20 Dec 2009, 11:45 |
|
Teehee 20 Dec 2009, 11:52
now I understand THANK YOU VERY MUCH!
|
|||
20 Dec 2009, 11:52 |
|
Teehee 20 Dec 2009, 12:03
One more question. How can I reallocate space?
ex: 1. untill 4096 bytes you fill with 'a'. 2. realloc to 8192. 3. 4096 untill 8192 byte you fill with 'b'. |
|||
20 Dec 2009, 12:03 |
|
revolution 20 Dec 2009, 12:09
You can't realloc virtual memory in any automatic way.
You have to allocate a new piece of memory. Copy in existing data. And then free the original memory. |
|||
20 Dec 2009, 12:09 |
|
revolution 20 Dec 2009, 12:13
Consider using VirtualAlloc to reserve space and just commit when you need it.
Or, consider using the LocalAlloc functions instead of the Virtual* functions. |
|||
20 Dec 2009, 12:13 |
|
Teehee 20 Dec 2009, 12:17
so i need to copy all bytes to the new buffer, then fill the rest with 'b' and release the last buffer? that's seems so slow
|
|||
20 Dec 2009, 12:17 |
|
Goto page 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.