flat assembler
Message board for the users of flat assembler.
Index
> Windows > VirtualAlloc or HeapAlloc |
Author |
|
vid 08 Oct 2007, 22:16
better for what? HeapAlloc may be better for some things, and VirtualAlloc for other things.
Also, i believe you can allocate more that SizeOfHeapReserve is. This is only size that should be quaranteed by windows to be present, and I wouln't be surprised if it is ignored by windows. |
|||
08 Oct 2007, 22:16 |
|
Hicel 08 Oct 2007, 23:05
Better for storing and reading an array of dwords, bytes, values whatever.
Yes you are right my WinXP seems to ignore it or just zeros some mem before. I guess I'll go with Virtual* API. Thanks, Hicel |
|||
08 Oct 2007, 23:05 |
|
UCM 09 Oct 2007, 01:17
I used to have some major memory leaking problems with VirtualAlloc, even though I tested it in OllyDbg and it was successfully freeing all of the memory.
Switching to HeapAlloc stopped the leaks, for some reason. Granted, it could easily be an error on my part; however, HeapAlloc seems to be more "resilient" to bugs. Just my experience. |
|||
09 Oct 2007, 01:17 |
|
vid 09 Oct 2007, 02:38
Hicel: what should those bytes, words, dwords represent? There is not such simple answer as "HeapAlloc is better than VirtualAlloc" (or vice-versa).
For example VirtualAlloc allows you to reserve block of memory, without commiting it, and then you can slowly commit parts of that block you need. This can sometimes save lot of time. VirtualAlloc is also much less limiting on size of allocated memory, and doesn't suffer so badly from segmentation. On other side, HeapAlloc is probably faster most of times, can allocate blocks smaller than 4KB, and is more error-tolerant (regardless of whether this is good or bad) |
|||
09 Oct 2007, 02:38 |
|
shoorick 09 Oct 2007, 04:54
HeapAlloc is better for memory blocks <4M. You may allocate more with HeapAlloc on 2k/xp, but you may fail HeapRealloc then to increase size. With VirtualAlloc you may reserve large memory block, and commit as many blocks as you need to save not used memory pages for the system.
|
|||
09 Oct 2007, 04:54 |
|
Hicel 14 Oct 2007, 19:25
Sorry for the late reply,
I can just say I used VirtualAlloc now and it works just fine. Thanks for the info about HeapAlloc anyway. vid the bytes words and so on were intended to be used as dynamic array in memory. Another question I got used to use edi for screwing arround in this array Code: invoke VirtualAlloc,... mov edi,eax ;store addr in edi mov edx ; element 5 dword mov [edi+edx*4],eax ;to save dword mov eax,[edi+edx*4] ;to load dword Is this ok or is another register standard for such things? also do I need to push/pop edi when changing it to save the old value? or does it not affect anything (Of course if I don't do something somewhere else in code with edi..) Regards, Hicel |
|||
14 Oct 2007, 19:25 |
|
shoorick 15 Oct 2007, 05:07
it is ok, just edi, esi and ebx could be better for indexed access, but there is no much difference in 32-bit mode. in 16-bit mode you just may not use edx,eax and ecx as indexing register, but if you do not use 16-bit mode - it's not too interesting. if you use registers in window procedure you must preserve ebx, edi and esi.
regards! |
|||
15 Oct 2007, 05:07 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.