Hello all! :)
I would know how to you create a string buffer? for store any value :)
I have said about malloc, but I see complicated :/
in runtime :P
thanks :B
for reasonably small buffers
.DATA?
Buffer db 128 dup(?)
that method is good if you are going to continually re-use the buffer or if you need global scope
there are also numerous ways to allocate a temporary buffer on the stack
for example, inside a PROC...
SomeFunction PROC
LOCAL Buffer[128]:BYTE
;
;
for larger buffers, there are LocalAlloc, GlobalAlloc, HeapAlloc, and VirtualAlloc functions
each function has a little different characteristics - pick the one that best suits your needs
for most buffers less than a few hundred Mbytes, i generally use HeapAlloc - it is simple and fast
INVOKE GetProcessHeap
mov hHeap,eax
INVOKE HeapAlloc,eax,HEAP_ZERO_MEMORY,NumberOfBytes
mov hBlock,eax
;
;hBlock = address of heap block
;
;when done using the buffer, you must free it
;
INVOKE HeapFree,hHeap,NULL,hBlock
if you do not require that it be zero'ed, replace the "HEAP_ZERO_MEMORY" with "NULL"
thanks dedndave, the truth that I will use it in inline asm, and for that reason did not want to make a call to the API, for that be fast :B
how large of a buffer do you need ?
is it temporary ?
I have the situation that, I cannot use the stack,API ( if posible)
The size I need to is 80-160 bytes and return the pointer of buffer , but this I can do, only I need a method :)
well - if you cannot use the stack, then just put it in the .DATA? (or _BSS) section
.DATA?
Buffer db 160 dup(?)
.CODE
mov eax,offset Buffer
Sorry, but edit my first post x3
I need in runtime : P
ok
you can't use a global allocation
can't use the stack
use HeapAlloc
you can initialize the hHeap value at the beginning of the program
INVOKE GetProcessHeap
mov hHeap,eax
then use HeapAlloc and HeapFree inline
INVOKE HeapAlloc,hHeap,HEAP_ZERO_MEMORY,NumberOfBytes
mov hBlock,eax
;
;
;
INVOKE HeapFree,hHeap,NULL,hBlock
it's quite fast, especially for a small buffer
even faster if you do not need it to be zero'ed
Ok very nice, dedndave thanks! :U