flat assembler
Message board for the users of flat assembler.

Index > Windows > Question on memory allocation...

Author
Thread Post new topic Reply to topic
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
I wonder when to use a buffer:

szBuffer db 1024 dup (?)

And when to use:

GlobaAlloc

LocalAlloc

HeapAlloc

VirtualAlloc

In what situations i must use everyone of this? Differences, situations when use one or other, and advantages/disadvantages...
Post 07 Sep 2008, 08:34
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
You allocate when you don't know the needed size in advance.
Post 07 Sep 2008, 09:01
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
dacid



Joined: 31 Aug 2008
Posts: 57
dacid
After a search in the forum and in msdn, i found that HeapAlloc & VirtualAlloc are the best choices to allocate. Seems that HeapAlloc for small allocations and VirtualAlloc for bigger ones.
Post 07 Sep 2008, 09:16
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:56; edited 1 time in total
Post 07 Sep 2008, 12:05
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
sub esp,xxx - buffer

but only if you are sure it won't be too big. Up to few kilobytes, taking more off the stack is not so good idea.
Post 07 Sep 2008, 13:02
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
HeapAlloc for generic memory allocations, Local/GlobalAlloc for those few APIs that require it (clipboard related, CreateStreamOnHGlobal, etc.). VirtuaAlloc for huge allocations.

Stack is fine for several kilobytes, and preferable to heap because it's much faster to add/sub esp than managing heap structures. Just remember to pre-touch pages to trigger guard-page allocation mechanism Smile
Post 07 Sep 2008, 13:31
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.