473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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::iterator iter1;

dwStart = GetTickCount();

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

dwStep1 = GetTickCount();

// Lookup items
for (dwIndex = 0;dwIndex < dwIterations;dwIndex++)
{
iter1 = SetTest1.find(dwIndex);
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.\nInserts = " << dwStep1 -
dwStart << "ms\nLookups = " << dwStep2 - dwStep1 << "ms\nDeletions = " <<
dwEnd - dwStep2 << "ms\nOverall = " << dwEnd - dwStart << "ms.\n";
// End old stl allocator test
}

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

Nov 23 '05 #1
3 1455
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_threshold(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_threshold. 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_threshold(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
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...
18
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...
7
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...
4
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 =...
1
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...
74
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...
94
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...
81
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...
12
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.