From Wayback Machine, this thread from before nidud's mass deletion of all of his posts
niduds deleted posts from this thread (https://web.archive.org/web/20140821094624/https://masm32.com/board/index.php?topic=3341.0)
Unfortunately the zip files were not archived (by Wayback Machine) and will not work.
XP MCE2005 (pro) SP3, prescott w/htt
Intel(R) Pentium(R) 4 CPU 3.00GHz (SSE3)
------------------------------------------------------
475699 cycles - LocalAlloc
477340 cycles - LocalAlloc
477033 cycles - LocalAlloc
14662124 cycles - HeapAlloc
14741803 cycles - HeapAlloc
14678539 cycles - HeapAlloc
15614816 cycles - GlobalAlloc
15559706 cycles - GlobalAlloc
15559654 cycles - GlobalAlloc
Interesting :t
So the question is, why do the others need so many cycles?
BTW the thread title is misleading; LocalAlloc is a Win32 function, you are creating something different...
you don't have to use a linker option - you can probe the stack down
it doesn't take many cycles because you get 4 Kb per loop pass
and - in some cases, the stack has been previously probed down part of the way
by the way - it does no good to time it more than one call per process instance :biggrin:
once the stack is probed down to some address - subsequent calls don't need to loop
;*****************************************************************************************************
OPTION PROLOGUE:None
OPTION EPILOGUE:None
ProbeStack PROC uSize:UINT
;Probe Stack to Bytes Requested
;Copyright Dedndave 6-2012
;
; Returns: EAX = probed-to stack pointer
; ECX = bytes requested
; EDX = top of stack
;---------------------------------------------------
ASSUME FS:Nothing
mov eax,esp
mov ecx,[esp+4]
add eax,8
push ebp
sub eax,ecx
mov ebp,esp
and al,-16 ;must be 4-aligned, 16-aligned optional (shown)
Probe0: push ecx
mov esp,fs:[8]
cmp eax,esp
jb Probe0
mov edx,esp
leave
ret 4
ASSUME FS:ERROR
ProbeStack ENDP
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
;*****************************************************************************************************
that's an older version - don't know if i have an updated one :P
deleted
Different strategies do different things, a high count of small allocations is always better done by allocating a single block and allocating pointers to parts of it as it is always a lot faster. It has to do with how the system allocates blocks of memory and what is the minimum size when a small block is allocated. For variable length strings the system has OLE strings which are part of the OLE string pool, if you need large blocks that can be swapped out to virtual memory, VirtualAlloc() is the right technique, most of the others interface with the same lower level function to provide memory so its more a choice of interface than performance.
LOCAL and GLOBAL Alloc are the same function as LocalAlloc() is a compatibility left over from Win16, GlobalAlloc() is required for a few old functions, the clipboard is one of them but it is only useful as a general purpose allocation strategy if you use the GMEM_FIXED flag and forget about GlobalLock() as it has assumptions from the Win16 days in its design.
Hi nidud,
Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz (SSE4)
------------------------------------------------------
1824805 cycles - GlobalAlloc
1872796 cycles - GlobalAlloc
1863379 cycles - GlobalAlloc
1483367 cycles - HeapAlloc
1558823 cycles - HeapAlloc
1545215 cycles - HeapAlloc
227101 cycles - LocalAlloc
228995 cycles - LocalAlloc
227467 cycles - LocalAlloc
Gunther
deleted
nidud,
something seems to be wrong, it doesnt work.
deleted
It works (XP SP3):
memory: 67108840
memory: 66708832
memory: 40308832
XP SP3 prescott w/htt
memory: 67108840
memory: 66708832
memory: 40308832
i'm confused :biggrin:
deleted
i know - the registers should be preserved before EBP is set, not after
that's because of the way LEAVE works on exit
i often write my own stack frame to get what i want...
http://masm32.com/board/index.php?topic=3326.msg35052#msg35052 (http://masm32.com/board/index.php?topic=3326.msg35052#msg35052)
deleted
there might be a way to write your own Prologue and Epilogue to do it
maybe even add the stack probe thing to make it crash-proof :biggrin:
deleted