flat assembler
Message board for the users of flat assembler.

Index > Windows > ..

Author
Thread Post new topic Reply to topic
pool



Joined: 08 Jan 2007
Posts: 97
pool 26 Aug 2009, 11:11
..


Last edited by pool on 17 Mar 2013, 11:58; edited 1 time in total
Post 26 Aug 2009, 11:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 26 Aug 2009, 11:40
Fastest for what? Big allocations? Small allocations? Do you want relocatable memory? Do you need control over access protections? Which version of Windows? How much free space do you have? Do you need to deallocate the memory later?

Sorry, there is no simple answer, you need to try the various options and see which one works best for your situation.
Post 26 Aug 2009, 11:40
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 26 Aug 2009, 11:54
sub esp,4
Post 26 Aug 2009, 11:54
View user's profile Send private message Visit poster's website Reply with quote
pool



Joined: 08 Jan 2007
Posts: 97
pool 26 Aug 2009, 12:10
..


Last edited by pool on 17 Mar 2013, 11:58; edited 1 time in total
Post 26 Aug 2009, 12:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 26 Aug 2009, 12:18
What is you deallocation strategy/pattern? FIFO, LIFO, random? Is the program going to run for extended periods? If so then memory fragmentation can create some problems with the wrong allocation type. You need to specify more about the alloc/dealloc profile.
Post 26 Aug 2009, 12:18
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 26 Aug 2009, 12:23
For me, the better one is, Windows VirtualAlloc, it is always aligned on at least a 16 byte boundary suitable for SSE data. The c function malloc is at best, aligned only to a 4 byte boudary. which is faster? I don't know.
Post 26 Aug 2009, 12:23
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 26 Aug 2009, 15:16
There's not much point in Local/GlobalAlloc, since they end up calling HeapAlloc internally (they do pass a magic flag value though, so when MSDN says you must use one of them (like with clipboard functions), better do so).

VirtualAlloc isn't suitable for small allocations - it has rather large overhead (always takes a kernel mode roundtrip) and has 64kb allocation granularity (on x86 anyway - if you wan to precise granularity, consult GetSystemInfo().dwAllocationGranularity).

Stack de/allocation is pretty darn fast, but isn't so suitable for long-lived data - and for shrinking/growing allocations or non-FIFO dealloc it's somewhat problematic. You're also limited in how much you can allocate from the PE stack reserve settings, and for "large" allocations you need to do stack probing (unless you only touch the memory backwards Smile).

HeapAlloc is a pretty decent default, and the low-fragmentation heap introduced with XP is OK (iirc they made it the default heap type in Vista - or perhaps it was Win7). There's been a lot of optimizations to the Heap* functions during the Windows versions, for speed as well as security.

For "extreme" situations you can roll your own allocator, or find an existing nice allocator like phkmalloc.
Post 26 Aug 2009, 15:16
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 26 Aug 2009, 15:43
f0dder wrote:
Stack de/allocation is pretty darn fast, but isn't so suitable for long-lived data - and for shrinking/growing allocations or non-FIFO dealloc it's somewhat problematic.
Erm, do you mean non-LIFO?
Post 26 Aug 2009, 15:43
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 26 Aug 2009, 22:58
revolution wrote:
f0dder wrote:
Stack de/allocation is pretty darn fast, but isn't so suitable for long-lived data - and for shrinking/growing allocations or non-FIFO dealloc it's somewhat problematic.
Erm, do you mean non-LIFO?
Yeah, sorry Smile - I was in a bit of a hurry when I wrote the post.

_________________
Image - carpe noctem
Post 26 Aug 2009, 22:58
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.