Slow x64 performance for free

I have a class like this (suppose all malloc succeeds)

class CMyClass { public: CMyClass() { lpData = malloc(128); }; ~CMyClass() { free(lpData); }; public: LPVOID lpData; }; 

then I do this:

 CMyClass *lpList = new CMyClass[32768]; delete [] lpList; 

The problem is that in x86 the code works fine and fast (some milliseconds end in debugging and release builds), but in x64 the delete call takes about 15 seconds to free up all the memory.

OS is Win7 x64.

Tips will be appreciated.

Regards, Mauro.

+6
source share
5 answers

It is possible that if you run the test application through the debugger, you are facing a performance issue with a bunch of Windows debugging. Add _NO_DEBUG_HEAP=1 to the environment settings for debuggee (in the properties of Project Properties → Configuration Properties → Debugging → Environment in Visual Studio 20xx) and see if your release level improves.

+7
source

I just tested this myself using gcc 4.6.1-1 on Debian (after adding typedef void *LPVOID ). There is no difference; both run instantly, even without any optimization.

I increased the length of the array to 1048576 to get a measurable runtime (0.161 s), which was the same for both IA32 and AMD64. I turned on optimization (-O3), and the time remained unchanged, but decreased to 0.157 s. -Os (optimization for size) had the same result.

Is it possible that you used different build options, for example, is it possible that some function for debugging memory access is enabled on AMD64?

+1
source

You either misdiagnose the problem or you have heap verification turned on. I would expect such disgusting performance if each malloc / free is called VirtualAlloc / VirtualFree, and if so, you somehow enabled memory debugging.

+1
source

Have you tried profiling both versions to see if there is anything obvious? Are the dimensions in the example the actual dimensions? My initial guess is that the 64-bit version requires (large) memory and forces the thrash OS, which will drastically decrease performance.

0
source

I ran the same code on x64 Windows 7 SP1, x64 Release build, VC10, SP1. X86 and x64 do exactly the same.

Maybe you missed something.

0
source

Source: https://habr.com/ru/post/891842/