flat assembler
Message board for the users of flat assembler.
Index
> Windows > VirtualAlloc trouble Goto page Previous 1, 2, 3 Next |
Author |
|
Teehee 20 Dec 2009, 12:19
so LocalAlloc you can to realloc?
|
|||
20 Dec 2009, 12:19 |
|
revolution 20 Dec 2009, 12:23
Yes you can realloc with the Local* functions. The OS takes care all the allocations and copying for you.
|
|||
20 Dec 2009, 12:23 |
|
revolution 20 Dec 2009, 12:29
The Local* functions are quite smart. They have strategies to minimise memory copying in many common circumstances. For small memory requirements the Local* functions are very good.
|
|||
20 Dec 2009, 12:29 |
|
Teehee 20 Dec 2009, 12:31
What do you call 'small memory requeriments'? untill 1Mb? untill 5mb? ...
|
|||
20 Dec 2009, 12:31 |
|
revolution 20 Dec 2009, 12:35
I usually use the Local* functions for memory allocations I expect to be less than 1MB. After that I would switch to Virtual* functions with reserve and commit as separate operations.
But it depends upon what you are doing. If you allocate a 16KB block at startup and never need to resize it then the Virtual* functions will be just fine (and probably more efficient). |
|||
20 Dec 2009, 12:35 |
|
Teehee 20 Dec 2009, 12:43
What's the best one to an Asm code editor? I think it's hard someone code more than 1mb of ASM-code in a same file...
|
|||
20 Dec 2009, 12:43 |
|
revolution 20 Dec 2009, 13:08
Teehee wrote: What's the best one to an Asm code editor? I think it's hard someone code more than 1mb of ASM-code in a same file... And a 1MB text file is easy to have, especially if you have predefined data tables. |
|||
20 Dec 2009, 13:08 |
|
Teehee 20 Dec 2009, 13:56
well, in my C# prototype, i used a dynamic string array, because this way its easier to control the lines (at least, its how i see), especially at render time.
The plain method, i think i'll need to count the lines sometimes (looking for '\n'). So it's seems slower. In my prototyp case, i just got a char index and a line index so i move these indexes to insert/remove chars/lines. But all operations like delete/copy selection need more code, bc it's not plain, it need to jump lines. However, i don't know to do dynamic arrays in Asm. But i don't have a strategy yet. We need to think which is the best method (if there is a 'best') . |
|||
20 Dec 2009, 13:56 |
|
revolution 20 Dec 2009, 14:06
Well without any defined strategy then I would suggest that attempting to guess the "best" memory functions is premature.
Perhaps I can suggest that you spend some time to layout the basic plan of how you will do things. Once you have the layout only then should you embark upon the finer details of what memory allocation functions to use. |
|||
20 Dec 2009, 14:06 |
|
Teehee 20 Dec 2009, 14:12
hmm.. i'm still testing plain/array methods. When I decide which to use, i back.
|
|||
20 Dec 2009, 14:12 |
|
Borsuc 20 Dec 2009, 17:12
Shouldn't you rather use Heap functions instead of Local?
|
|||
20 Dec 2009, 17:12 |
|
revolution 20 Dec 2009, 17:21
Borsuc: What is the advantage of Heap* functions?
This quote is something that always bothers me about using the heap: Win32 manual wrote: Memory allocated by HeapAlloc is not movable. Because the system cannot compact a private heap, the heap can become fragmented. |
|||
20 Dec 2009, 17:21 |
|
Borsuc 20 Dec 2009, 17:32
Well the Heap functions are high-level functions for a large virtual reserved block. It uses probably a linked list inside that block for its memory operations (offset & length for an allocation probably). So of course it can become fragmented, like files can be stored inside a "block" (harddrive) but then if you delete files and add others it will get fragmented in the process.
I don't know much about the Local and Global functions but I remember them being 'deprecated' so I thought they had less functionality and were not advised to be used. (but kept for backward compatibility only) PE has a initial heap of a given commit & reserve size, so now you know what it does. You can also create new heaps (blocks) with HeapCreate etc... I think Local and Global use pre-defined heaps anyway. |
|||
20 Dec 2009, 17:32 |
|
revolution 20 Dec 2009, 17:44
Compared to Heap* I know the Local* functions are not constrained by any initial Create function.
The Local* functions are pretty smart, I have used them to allocate blocks of memory 1GB+ with no problems. Although the alignment is not guaranteed in the same way the Virtual* does things. I have also read elsewhere that if you keep some Local memory regions unlocked that the Local(Re)Alloc can shuffle the unlocked regions around (i.e. defragment) to make space for new requests. |
|||
20 Dec 2009, 17:44 |
|
bitshifter 20 Dec 2009, 18:09
Alternatively you can use HeapAlloc to get a huge chunk and manage it yourself.
|
|||
20 Dec 2009, 18:09 |
|
revolution 20 Dec 2009, 18:18
bitshifter wrote: Alternatively you can use HeapAlloc to get a huge chunk and manage it yourself. |
|||
20 Dec 2009, 18:18 |
|
Borsuc 20 Dec 2009, 20:21
Quote: The global and local functions are supported for porting from 16-bit code, or for maintaining source code compatibility with 16-bit Windows. Starting with 32-bit Windows, the global and local functions are implemented as wrapper functions that call the corresponding heap functions using a handle to the process's default heap. Therefore, the global and local functions have greater overhead than other memory management functions. How did you manage to allocate 1GB with the default heap? What PE header did you use, that's a lot of heap pages to reserve. _________________ Previously known as The_Grey_Beast |
|||
20 Dec 2009, 20:21 |
|
revolution 21 Dec 2009, 00:53
Try it for yourself. Just keep asking for more memory until you get an error.
|
|||
21 Dec 2009, 00:53 |
|
revolution 21 Dec 2009, 01:09
Something for you to play with:
Code: ALLOC_SIZE = 100 shl 20 include 'win32ax.inc' .code begin: mov ebx,0 .again: invoke LocalAlloc,LMEM_FIXED,ALLOC_SIZE cmp eax,0 jz .error add ebx,ALLOC_SIZE jmp .again .error: sub esp,1 shl 10 mov esi,esp cinvoke wsprintf,esi,'Allocated %u bytes',ebx invoke MessageBox,0,esi,'LocalAlloc testing',0 invoke ExitProcess,0 .end begin |
|||
21 Dec 2009, 01:09 |
|
Goto page Previous 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.