🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8594

malloc: where is the catch?

#8594
From: Azazello
Date: Thu, 07 Oct 2004 13:37
30 lines
2234 bytes
Hi there,

Haven't been here for a while, glad to see that TeamB is still active. You guys rock! ;)

Now to the topic. I've been playing with multithreading under Win32 and as a part of it ran into a question about optimal memory allocation, which provoked me to test speed of different memory allocation functions. The results were, should I say, interesting, and though most of you ran these tests yourself, I'll take the liberty to share them.

Setup: 10000 cycles of allocation/deallocations of 0x2000 bytes; Performance Counter used as timer.

Results ( normalized to be more readable ):
1. HeapAlloc/HeapFree 
Non-serialized, non-growable heap = 100.
Non-serialized, growable heap = 100.
Serialized, non-growable heap = 100.
Serialized/growable heap = 52.
Process default heap = 88.

2. VirtualAlloc/VirtualFree (commit/decommit) = 33.

3. calloc/free (to compare with VirualAlloc)= 16.

4. malloc/free (same as new/delete) = 3.

Questions:
1. Can someone explain to me how malloc (serialized function, by the way) can be 33 (SIC!) times faster than heap functions and 11 times faster than VirtualAlloc (ok, VirtualAlloc zeros memory, but still, calloc is 2 times faster)?
2. Why Non-serialized/non-growable heap is twice slower than serialized/growable heap? Shouldn't it be other way around?
3. malloc seems to be too good to be true, so where is the catch? What does not malloc do compare to other functions?

Thanks,
Azazello.
Technical Details
Message-ID: <4165469c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,50f14b41a5262fc0,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Azazello" <snimi_potniki@hotmail.com>
Sender: "Azazello" <snimi_potniki@hotmail.com>
Reply-To: "Azazello" <snimi_potniki@hotmail.com>
Subject: malloc: where is the catch?
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 142.58.249.61     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4165469c$1@newsgroups.borland.com>
Date: 7 Oct 2004 06:37:32 -0700
X-Trace: newsgroups.borland.com 1097156252 207.105.83.66 (7 Oct 2004 06:37:32 -0700)
Lines: 30
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail