Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual C++ new operator fails

Status
Not open for further replies.

Mburnside

Programmer
May 12, 2005
2
US
I have a problem with new operator failing to allocate memory sometimes when running the piece of code below. Usually when I hits between 200 to 400 it fails.

There is a lot more going on within the program other than this piece of code and this code is contained within a dll.
The machine that the code is running on is windows xp sp2 with 1G RAM so I do not understand how it can fail to allocate memory and I have verified that there is enough memory available.

Does anyone have any ideas why new fails in this suggestion or why new would fail at all?

thanks

char **m_pszDotCodeLine;

m_pszDotCodeLine = new char*[1000];

for (i = 0; i < 1000; i++)
{
try
{
m_pszDotCodeLine = new char[200];
}
catch(...)
{
throw Exception(pstDLLError, INSUFF_MEM, FAIL, P_NEWNOTE, 999);
)
memset(m_pszDotCodeLine, NULL, 200);
}
}
 
Does it always fail at the same memory size?
Does it happen in Debug and Release modes?
 
No the memory address is always different.

Only release mode and it's weird as the code only fails every so often at this one customer site. They have told us it happens on all their machines. We have about 400 customers using the program and none of them claim that they have seen any problems in that area.
 
Your snippet has 2 syntax errors (alas;).
May be:
1. The heap was corrupted before this stage.
2. There is incorrect (old?) RTL dll in the site (try a static linkage with RTL).
etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top