C++分配的奇怪减速

And*_*eff 9 c++ memory allocation memory-fragmentation

有人可以告诉我为什么会发生以下事情:

我有2台电脑:

  1. 我的工作补偿
  2. 服务器

我维护C++程序(msvc 2005 c ++编译),它只在服务器上运行得太慢,但在我的comp上却没有.

我进行了测量(GetThreadTimes等)并且肯定可以说是狭窄的地方 - 它的内存分配(new/malloc).它只发生在服务器上!

我可以声称它是由于内存碎片而发生的,因为第一次服务器程序实例工作正常,只有在数据重新加载到内存(1-1.5百万分配/释放)后才开始在allocs上失去时间.

如果由于两台计算机(我的comp和服务器)上的内存碎片而看到相同的行为,我不会感到惊讶,但我看到的是:1).在我的comp分配上需要约5%的时间(不完全但有些像这样)2).在服务器上,这些分配需要大约75%的时间

怎么会发生这种情况?什么可能会减慢服务器计算机上的C++分配速度,同时它可以用于我的工作站.哪里可能有区别?它可能与OS级内存管理功能有关吗?因为C++级别管理器在两种情况下都是一样的.

以下是两种配置:

1).我的电脑(其中alloc占用约5%):

OS Name:                   Microsoft Windows 7 Enterprise 
OS Version:                6.1.7600 N/A Build 7600
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          Windows User
Original Install Date:     16/09/2011, 19:37:43
System Boot Time:          05/04/2013, 11:58:11
System Model:              7304A58
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 23 Stepping 10 GenuineIntel ~2642 Mhz
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume2
System Locale:             ru;Russian
Input Locale:              en-us;English (United States)
Total Physical Memory:     4,061 MB
Available Physical Memory: 872 MB
Virtual Memory: Max Size:  8,121 MB
Virtual Memory: Available: 4,579 MB
Virtual Memory: In Use:    3,542 MB
Page File Location(s):     C:\pagefile.sys
Run Code Online (Sandbox Code Playgroud)

2).服务器(其中alloc占用约75%):

OS Name:                   Microsoft(R) Windows(R) Server 2003, Enterprise Edition
OS Version:                5.2.3790 Service Pack 2 Build 3790
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Server
OS Build Type:             Multiprocessor Free
Original Install Date:     11/12/2008, 01:22:57
System Up Time:            1 Days, 8 Hours, 35 Minutes, 52 Seconds
System Manufacturer:       HP
System Model:              ProLiant BL685c G5  
System Type:               X86-based PC
Processor(s):              4 Processor(s) Installed.
                           [01]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
                           [02]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
                           [03]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
                           [04]: x86 Family 16 Model 2 Stepping 3 AuthenticAMD ~2210 Mhz
Windows Directory:         C:\WINNT
System Directory:          C:\WINNT\system32
Boot Device:               \Device\HarddiskVolume1
Total Physical Memory:     65,534 MB
Available Physical Memory: 61,284 MB
Page File: Max Size:       97,696 MB
Page File: Available:      93,445 MB
Page File: In Use:         4,251 MB
Page File Location(s):     C:\pagefile.sys
                           D:\pagefile1\pagefile.sys
                           D:\pagefile2\pagefile.sys
                           D:\pagefile3\pagefile.sys
                           D:\pagefile4\pagefile.sys
                           D:\pagefile5\pagefile.sys
                           D:\pagefile6\pagefile.sys
                           D:\pagefile7\pagefile.sys
Run Code Online (Sandbox Code Playgroud)

将不胜感激澄清这个问题.

Quo*_*nux 4

问题可能是内存函数仅使用一个互斥锁来锁定内存以进行分配和释放。

  • 有趣的。并引用此线程(http://stackoverflow.com/questions/4859263/can-multithreading-speed-up-memory-allocation)-“...如果启用低碎片堆,操作系统堆函数将执行得相当好,这是自 Windows Vista 以来的默认设置(在 Windows XP 上,应用程序可以通过简单调用 HeapSetInformation() 来启用它)。启用 LFH 后,Windows 堆的性能可与最快的可用其他分配器相媲美” (3认同)
  • MSVC++ 2005 并不是最新版本,Server 2003 也不是最新版本。Windows 7 计算机默认启用低碎片堆。因此,这是一个相当可信的答案。我希望新版本能够更好地与 4x4 核心机器配合使用。作为解决方法,请尝试其他分配器,例如 [jemalloc](http://www.canonware.com/jemalloc) (2认同)