开发者

Slow performance on x64 free

I have a class like this (assume all malloc's succeedes)

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

  ~CMyClass()
  {
  free(lpData);
  };

public:
  LPVOID lpData;
};

then I execute this:

CMyClass *lpList = new CMyClass[32768];

delete [] lpLis开发者_运维百科t;

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

O.S. is Win7 x64.

Hints will be appreciated.

Regards, Mauro.


It is possible that if you are running your test app through a debugger that you are hitting some performance issue with the Windows debug heap. Add _NO_DEBUG_HEAP=1 to the environment settings for the debuggee (in the Project Properties->Configuration Properties->Debugging->Environment property under Visual Studio 20xx) and see if that improves your deallocation perf.


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

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

Is it possible you used different build options, like maybe you have some sort of memory access debugging enabled on AMD64?


You are either misdiagnosing the problem or you have some heap checking turned on. I would expect so lousy performance if each malloc/free called VirtualAlloc/VirtualFree, and if that is the case, you have enabled memory debugging somehow somewhere.


Did you try profiling both versions to see if there's anything obvious? Are the sizes in the example the actual sizes? My initial guess is that the 64-bit version needs (a lot) more memory and causes the OS to thrash which would drastically reduce performance.


I ran the same code on x64 Windows 7 SP1, x64 Release build, VC10, SP1. The x86 and x64 performs exactly the same way.

May you are missing something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜