473,569 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory allocation performance problems vs .net

We have been trying to upgrade all our C++ projects from VC6 to VS .Net2003
for a while (before VS 2005 arrived), and seem to be stuck now because of the
performance degradation seen for the same code when compiled by the new
compiler compared to being compiled by VC 6 compiler.
Originally we thought it was the STL libraries that had killed all
performance but it seems to be a general memory allocation problem in VS .Net
2003 (and also in VS 2005). Not only is the performance very poor in
comparison but seems to be inconsistent for timings too. When running the
code listed below on VS 6 both sets of timings are about the same, when
running on VS .Net (2003 and 2005) the timings are very much slower than
before but also inconsistent, then second set of output results are between
one and half to twice as slow as the first set. Please can someone explain
why this would be?

Below is the code snippet, which can be compilied under any of the dev
environments using any of the projects options you feel like, and either
debug or release, as long as you compare lilke with like you will same the
results as below).
The results shown here are comparing vc7.1 and vc6 release builds statically
linked with multi-threaded libraries:

VC 7.1
Old STL allocator test results.
Inserts = 3500ms
Lookups = 1312ms
Deletions = 844ms
Overall = 5656ms.
Old STL allocator test results.
Inserts = 4953ms
Lookups = 2860ms
Deletions = 843ms
Overall = 8656ms.

vc6
Old STL allocator test results.
Inserts = 1062ms
Lookups = 219ms
Deletions = 859ms
Overall = 2140ms.
Old STL allocator test results.
Inserts = 1172ms
Lookups = 203ms
Deletions = 875ms
Overall = 2250ms.

Source code:

#include <windows.h>
#include <iostream>
#include <set>

typedef std::set<DWORD, std::less<DWORD > >
COldSTLSet;

void STLTest1(DWORD dwIterations)
{
DWORD dwStart, dwStep1, dwStep2, dwEnd;
DWORD dwIndex;

// now use our own allocator object for an STL implementation
COldSTLSet SetTest1;

COldSTLSet::ite rator iter1;

dwStart = GetTickCount();

// Old STL allocator type
// Insert items
for (dwIndex = 0;dwIndex < dwIterations;dw Index++)
SetTest1.insert (dwIndex);

dwStep1 = GetTickCount();

// Lookup items
for (dwIndex = 0;dwIndex < dwIterations;dw Index++)
{
iter1 = SetTest1.find(d wIndex);
if (iter1 == SetTest1.end())
std::cout << "Lookup failed.\n";
}
dwStep2 = GetTickCount();

// Delete items
while(!SetTest1 .empty())
{
iter1 = SetTest1.begin( );
SetTest1.erase( iter1);
}
dwEnd = GetTickCount();

std::cout << "Old STL allocator test results.\nInser ts = " << dwStep1 -
dwStart << "ms\nLookup s = " << dwStep2 - dwStep1 << "ms\nDeleti ons = " <<
dwEnd - dwStep2 << "ms\nOveral l = " << dwEnd - dwStart << "ms.\n";
// End old stl allocator test
}

int main(int argc, char* argv[])
{
DWORD dwIterations = 1500000;
STLTest1(dwIter ations);
Sleep(5000);
STLTest1(dwIter ations);
return 0;
}

Nov 23 '05 #1
3 1467
EasyKev wrote:
We have been trying to upgrade all our C++ projects from VC6 to VS
.Net2003 for a while (before VS 2005 arrived), and seem to be stuck
now because of the performance degradation seen for the same code
when compiled by the new compiler compared to being compiled by VC 6
compiler.
Originally we thought it was the STL libraries that had killed all
performance but it seems to be a general memory allocation problem in
VS .Net 2003 (and also in VS 2005). Not only is the performance very
poor in comparison but seems to be inconsistent for timings too. When
running the code listed below on VS 6 both sets of timings are about
the same, when running on VS .Net (2003 and 2005) the timings are
very much slower than before but also inconsistent, then second set
of output results are between one and half to twice as slow as the
first set. Please can someone explain why this would be?

Below is the code snippet, which can be compilied under any of the dev
environments using any of the projects options you feel like, and
either debug or release, as long as you compare lilke with like you
will same the results as below).
The results shown here are comparing vc7.1 and vc6 release builds
statically linked with multi-threaded libraries:


Others have reported similar differences and have found that changing the
small block heap threshold solved the performance difference. See

http://msdn2.microsoft.com/en-us/library/a6x53890.aspx

while this link doesn't say, I believe that the defaults changed between VC6
and VC7 and that that's the source of most allocation-related performance
differences when porting from VC6.

-cd
Nov 23 '05 #2
Hi,
We have been trying to upgrade all our C++ projects from VC6
to VS .Net2003 for a while (before VS 2005 arrived), and
seem to be stuck now because of the performance degradation

<skip>
Others have reported similar differences and have found that
changing the small block heap threshold solved the performance
difference. See

http://msdn2.microsoft.com/en-us/library/a6x53890.aspx


Here the results of the original snippet on my machine:

Old STL allocator test results.
Inserts = 1328ms
Lookups = 593ms
Deletions = 485ms
Overall = 2406ms.
Old STL allocator test results.
Inserts = 4422ms
Lookups = 2531ms
Deletions = 469ms
Overall = 7422ms.

And this is output after _set_sbh_thresh old(1016) addition in main:

Old STL allocator test results.
Inserts = 594ms
Lookups = 203ms
Deletions = 219ms
Overall = 1016ms.
Old STL allocator test results.
Inserts = 531ms
Lookups = 172ms
Deletions = 235ms
Overall = 938ms.
Nov 23 '05 #3
Thank you both for your replies to this.

We have tried this in one of our applications. It does improve the
performance for VC7.1 and VC8 applications for the majority of situations and
we will use this to resolve these issues.

The problem that I unfortunately have not been able to track down is under
some other circumstances the performance actually drops off when using the
_set_sbh_thresh old. If and when I can track down the circumstances when the
drop occurs I will post again, with some sample code to replicate this
problem.

Thanks,

Kevin

"Serge Skorokhodov (216716244)" wrote:
Hi,
We have been trying to upgrade all our C++ projects from VC6
to VS .Net2003 for a while (before VS 2005 arrived), and
seem to be stuck now because of the performance degradation


<skip>
Others have reported similar differences and have found that
changing the small block heap threshold solved the performance
difference. See

http://msdn2.microsoft.com/en-us/library/a6x53890.aspx


Here the results of the original snippet on my machine:

Old STL allocator test results.
Inserts = 1328ms
Lookups = 593ms
Deletions = 485ms
Overall = 2406ms.
Old STL allocator test results.
Inserts = 4422ms
Lookups = 2531ms
Deletions = 469ms
Overall = 7422ms.

And this is output after _set_sbh_thresh old(1016) addition in main:

Old STL allocator test results.
Inserts = 594ms
Lookups = 203ms
Deletions = 219ms
Overall = 1016ms.
Old STL allocator test results.
Inserts = 531ms
Lookups = 172ms
Deletions = 235ms
Overall = 938ms.

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3655
by: Alan Gifford | last post by:
I wrote a program to make sure that new would throw a bad_alloc exception if more memory was requested than was available. On my system, new allocates up to 2931 MBs of memory (I don't have that much, not even with swap) before throwing an exception. When the program tries to fill in the allocated memory with data, it is killed after using...
18
6660
by: Tron Thomas | last post by:
Given the following information about memory management in C++: ----- The c-runtime dynamic memory manager (and most other commercial memory managers) has issues with fragmentation similar to a hard drive file system. Over time, the more often use call new/delete or alloc/free, there will be gaps and fragments in the heap. This can lead...
7
1618
by: Gumby | last post by:
I want to make a two-d array of unsigned ints that I can change the size of as I need more memory. To do this I put in the h file a simple pointer to the memory and row/col variables to retain the current size. private: unsigned int* mergeKeyTable; unsigned int rows; unsigned int cols;
4
6759
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a = Linux galahad 2.4.19-64GB-SMP #1 SMP /etc/sysctl.conf kernel.shmmax=268435456
1
2061
by: spiff | last post by:
We are migrating from VC++ 6 to VC++ 2003. It is a plain, unmanaged application with both C and C++ source. When running the debug build, even outside the debugger, the memory allocation/deallocation performance appears to be orders of magnitude slower than in VC++ 6. The release build runs fine - no performance problems. We've rewritten some...
74
4620
by: ballpointpenthief | last post by:
If I have malloc()'ed a pointer and want to read from it as if it were an array, I need to know that I won't be reading past the last index. If this is a pointer to a pointer, a common technique seems to be setting a NULL pointer to the end of the list, and here we know that the allocated memory has been exhausted. All good. When this is...
94
4665
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring that I found inside of a string. Any ideas?
81
4516
by: Peter Olcott | last post by:
It looks like System::Collections::Generic.List throws and OUT_OF_MEMORY exception whenever memory allocated exceeds 256 MB. I have 1024 MB on my system so I am not even out of physical RAM, much less virtual memory. Are other people experiencing this same problem?
12
2987
by: David Given | last post by:
I have a situation where I need to be able to allocate chunks on unmapped virtual memory. Because the memory I'm allocating isn't mapped, I can't use a normal memory allocator, as most of them want to store their metadata about the free list in the unused holes in the heap. Instead, I need a memory allocator that stores its metadata...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.