A comparison of the speed of HeapAlloc/HeapFree vs HeapReAlloc (full code attached, plain Masm32).
First, the alloc/free loop:
push [esi+4*ebx] ; old pointer
push rv(nrandom, 1000) ; get a random number
mov [esi+4*ebx], rv(HeapAlloc, procHeap, HEAP_GENERATE_EXCEPTIONS, eax)
pop edx
invoke lstrcpyn, [esi+4*ebx], offset somestring, edx ; fill the string
pop ecx
jecxz @F
invoke HeapFree, procHeap, 0, ecx
@@: inc ebx
Second, the realloc loop: push rv(nrandom, 1000) ; get a random number
mov [esi+4*ebx], rv(HeapReAlloc, procHeap, HEAP_GENERATE_EXCEPTIONS, [esi+4*ebx], eax)
pop edx
invoke lstrcpyn, [esi+4*ebx], offset somestring, edx ; fill the string
inc ebx
alloc#
+94 ms
+468 ms
+826 ms
+390 ms
+624 ms
+297 ms
+468 ms
+437 ms
+406 ms
+265 ms
realloc
+94 ms
+78 ms
+78 ms
+78 ms
+78 ms
+78 ms
+78 ms
+78 ms
+78 ms
+78 ms
ok?