Changing the heap allocator
Hi,
I'm working on a project where I've replaced Microsoft's (terrible) heap
allocator with the Doug Lea allocator. There seems to be some cases
where the Windows XP allocator is 500 times slower than it should be.
This made my program take minutes rather than seconds to run. To try to
understand what kind of allocation patterns cause the behaviour I wrote
a small console application (see below). After playing around with
different allocation patterns for half an hour I found a case where the
pathological behaviour appeared. I'm none the wiser about the problem.
For example, moving the malloc(301) statement before the 7 x
malloc(1000) makes the problem go away! However, given the ease with
which I rediscovered the problem, I wonder why there aren't more
complaints about Microsoft's heap allocator. With some allocation
patterns I have seen the allocator fall below 1kHz on a Pentium IV 2GHz
machine!
I've created a library that exports alternative versions of operator new
and operator delete, by using a def file as follows
EXPORTS
??2@YAPAXI@Z
??3@YAXPAX@Z
I've had to do some hacky things to make it work with the STL (because
of msvcp60.dll) , but that's another story!
Now my question : I want to use boost, but need to work out how to make
it use a different allocator. Will I need to rebuild the boost dlls
(such as boost_python.dll), against my static library?
Regards,
David Barrett-Lennard
/////////////////////// heap allocation test ///////////////////////////
#include <iostream>
#include
re: (because of msvcp60.dll) that may sum up the entire problem.... VC++6.0 is broken...period...simple statement of fact it was replaced 2 years ago by .net then again by .net2003 you may wish to test with a current version At Wednesday 2004-04-07 19:54, you wrote:
Hi,
I'm working on a project where I've replaced Microsoft's (terrible) heap allocator with the Doug Lea allocator. There seems to be some cases where the Windows XP allocator is 500 times slower than it should be. This made my program take minutes rather than seconds to run. To try to understand what kind of allocation patterns cause the behaviour I wrote a small console application (see below). After playing around with different allocation patterns for half an hour I found a case where the pathological behaviour appeared. I'm none the wiser about the problem. For example, moving the malloc(301) statement before the 7 x malloc(1000) makes the problem go away! However, given the ease with which I rediscovered the problem, I wonder why there aren't more complaints about Microsoft's heap allocator. With some allocation patterns I have seen the allocator fall below 1kHz on a Pentium IV 2GHz machine!
I've created a library that exports alternative versions of operator new and operator delete, by using a def file as follows
EXPORTS ??2@YAPAXI@Z ??3@YAXPAX@Z
I've had to do some hacky things to make it work with the STL (because of msvcp60.dll) , but that's another story!
Now my question : I want to use boost, but need to work out how to make it use a different allocator. Will I need to rebuild the boost dlls (such as boost_python.dll), against my static library?
Regards, David Barrett-Lennard
/////////////////////// heap allocation test ///////////////////////////
#include <iostream> #include
int main(int argc, char* argv[]) { for (int count=1 ; count <= 5 ; ++count) { int n1 = 0, n2 = 0; clock_t start = clock(); { const int NUM = 10000; void* L[NUM*7]; for (int i=0 ; i < NUM ; ++i) { for (int j=0 ; j < 7 ; ++j) L[n1++] = malloc(1000); void* leak = malloc(301); ++n2; } for (int k=n1-1 ; k >= 0 ; --k) free(L[k]); } clock_t elapsed = clock()-start; if (elapsed) { std::cout << "Time = " << elapsed << " ms" << " Rate = " << 1000 * (n1 + n2) / elapsed << " Hz" << std::endl; } } return 0; }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
Hello, Victor!
You wrote to
Hi Victor, Your first run took 1/4 sec and the second run took 21 sec. These are similar to the times I get. If you play around with the settings you can get the Microsoft allocator down to below 1kHz, which is laughable. On my Pentium IV @ 2GHz machine, Doug Lea's allocator consistently runs at about 1.3 MHz! Any program which is bounded by the allocator will benefit by replacing with a decent one. Even when I don't get the pathological behaviour I usually get (at least) 2 to 3 times speed up. An STL set uses a red-black tree and is a good candidate because it is heap intensive. Eg copying a set<int> with 1024 entries increases from 950 Hz to 2.5 kHz. Inserting these elements into the set increases from 390 kHz to 1.4 MHz. Has anyone out there tried to replace the heap allocator for an application using boost under Windows? - David
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Victor Snezhko Sent: Monday, 12 April 2004 12:46 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Changing the heap allocator
Hello, Victor! You wrote to
on Sat, 10 Apr 2004 01:16:30 -0700: VAW> re: (because of msvcp60.dll) VAW> that may sum up the entire problem.... VC++6.0 is VAW> broken...period...simple statement of fact VAW> it was replaced 2 years ago by .net then again by .net2003 VAW> you may wish to test with a current version
The same behaviour with VC .NET 2003:
[d:/temp/temp/temp]$ make all cl /O2 /GX temp.cpp /Fetemp-vc71.exe Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86 [...] /out:temp-vc71.exe
[d:/temp/temp/temp]$ ./temp-vc71.exe Time = 240 ms Rate = 333333 Hz Time = 21212 ms Rate = 3771 Hz Time = 641 ms Rate = 124804 Hz Time = 18768 ms Rate = 4262 Hz Time = 150 ms Rate = 533333 Hz
-- With best regards, Victor Snezhko. E-mail: snezhko@indorsoft.ru
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Victor A. Wagner Jr. Sent: Saturday, 10 April 2004 4:16 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Changing the heap allocator
re: (because of msvcp60.dll) that may sum up the entire problem.... VC++6.0 is broken...period...simple statement of fact it was replaced 2 years ago by .net then again by .net2003 you may wish to test with a current version
Hi,
I'm working on a project where I've replaced Microsoft's (terrible) heap allocator with the Doug Lea allocator. There seems to be some cases where the Windows XP allocator is 500 times slower than it should be. This made my program take minutes rather than seconds to run. To try to understand what kind of allocation patterns cause the behaviour I wrote a small console application (see below). After playing around with different allocation patterns for half an hour I found a case where the
At Wednesday 2004-04-07 19:54, you wrote: pathological
behaviour appeared. I'm none the wiser about the problem. For example, moving the malloc(301) statement before the 7 x malloc(1000) makes
problem go away! However, given the ease with which I rediscovered
Hi Victor, The CRT library that comes with VC is only a thin wrapper for the heap allocator implemented in kernel.dll - see HeapAlloc() in MSDN. For that reason it won't make any difference what version of VC is used. Note that I haven't seen the pathological behavior with Windows 98. Does anyone know how to enable the LFH (low fragmentation heap) for the heap created by the VC CRT? - David the the
problem, I wonder why there aren't more complaints about Microsoft's heap allocator. With some allocation patterns I have seen the allocator fall below 1kHz on a Pentium IV 2GHz machine!
I've created a library that exports alternative versions of operator new and operator delete, by using a def file as follows
EXPORTS ??2@YAPAXI@Z ??3@YAXPAX@Z
I've had to do some hacky things to make it work with the STL (because of msvcp60.dll) , but that's another story!
Now my question : I want to use boost, but need to work out how to make it use a different allocator. Will I need to rebuild the boost dlls (such as boost_python.dll), against my static library?
Regards, David Barrett-Lennard
/////////////////////// heap allocation test ///////////////////////////
#include <iostream> #include
int main(int argc, char* argv[]) { for (int count=1 ; count <= 5 ; ++count) { int n1 = 0, n2 = 0; clock_t start = clock(); { const int NUM = 10000; void* L[NUM*7]; for (int i=0 ; i < NUM ; ++i) { for (int j=0 ; j < 7 ; ++j) L[n1++] = malloc(1000); void* leak = malloc(301); ++n2; } for (int k=n1-1 ; k >= 0 ; --k) free(L[k]); } clock_t elapsed = clock()-start; if (elapsed) { std::cout << "Time = " << elapsed << " ms" << " Rate = " << 1000 * (n1 + n2) / elapsed << " Hz" << std::endl; } } return 0; }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
David Barrett-Lennard
-
Victor A. Wagner Jr.
-
Victor Snezhko