Sign in to follow this  

Error - Invalid Allocation Size, How do I fix this?

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am using C++. I have an iterator to an object and in that object is a string that I have previously set to "Name1". I try to access that variable in another function and I get this error: "Invalid allocation size - FEEEFF14 (exceeded 7ffdefff) First-chance exception at 0x7c81eb33 in Project.exe: Microsoft C++ exception: std::bad_alloc @ 0x0012f4e0." //somethings wrong with my string (itApple->m_sShortName):
//before this point a specfic apple is found, eg itApple points to that 
//specific apple

//iterator itApple does work, as it prints out this variable:
g_Log<<"itApple->m_sLongName="<<itApple->m_sLongName<<endl;

//loop
list<string>::iterator itString=lstStrings.begin();
while(itString!=lstStrings.end())
{    
     //crashes on the following line
     //something is wrong with itApple->m_sShortName, it's a string
     g_Log<<"itApple->m_sShortName="<<itApple->m_sShortName<<endl;

     //function that needs string and 'short name'
     //would crash here if it made it to this point
     func((*itString),itApple->m_sShortName);
						
     ++itString;//continue
}





Anyone able to help? [Edited by - utilae on August 3, 2005 5:56:56 AM]

Share this post


Link to post
Share on other sites
I don't know what compiler you're using, but typically when you delete or free memory in windows the runtime library will fill that freed memory in with the value 0xFEEEFEEE. Looking at your error, I see the value FEEEFF14 and it leads me to believe that somehow you are accessing freed memory. Make sure that whatever object this function is a member of has not been deleted before you call this function.

Share this post


Link to post
Share on other sites
Quote:
Original post by JoshM
I don't know what compiler you're using

I'm using Visual Studio .NET 2003

Quote:
Original post by JoshM
Looking at your error, I see the value FEEEFF14 and it leads me to believe that somehow you are accessing freed memory. Make sure that whatever object this function is a member of has not been deleted before you call this function.

It's strange. I can access one member of the object, but when I access the one I'm having a problem with, it crashes.

Share this post


Link to post
Share on other sites
Hi there.

I'm a little confused by you code snippet.

Is Apple also an iterator to an std::list<string>?

The snippet seems to be loping thru lstString<> BUT you're not using itString...should the code look like:


//loop
list<string>::iterator itString=lstStrings.begin();
while(itString!=lstStrings.end())
{
//crashes on the following line
//something is wrong with Apple->m_sShortName, it's a string
g_Log<<"itString->m_sShortName="<<itString->m_sShortName<<endl;

//function that needs string
func(itString->m_sShortName);

++itString;//continue
}



Is the posted code the actual code in your project?

Could you post the code that populates your fruit list and the code the deals with the apple iterator.

Share this post


Link to post
Share on other sites
Sorry, I guess I should of showed that I was using the string iterator. I have edited my original post. Basically I iterate through a list of strings and use the string ( (*itString) ) in the function.

Share this post


Link to post
Share on other sites
Here's the code where I allocate shortname and longname. Then I run another function that contains the code in my first post.

void CAppleManager::SomeFunc(const string &sShortName,const string &sLongName)
{
CApple newApple;
newApple.m_sShortName=sShortName;
newApple.m_sLongName=sLongName;

//The string is accessable in this function, but I can't access it outside
//of this function. I have not changed or done anything more
//with these variables. Once they are set here, they are not touched again.
//They are only read.
g_LognewApple.m_sShortName="<<newApple.m_sShortName<<endl;

m_lstApples.push_back(newApple);//vector full of apples
}




If my problem cannot be solved directly from the code here, could someone give me some insight on the possible causes of this error and an in depth meaning of this error, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by perfectly_dark
Sounds to me like you're trying to allocate more memory than the system can handle, though I don't see that in your code

I don't know how that can happen. I have 640MB of ram.

Quote:
Original post by perfectly_dark
do you dynamically allocate memory somewhere?

No.

Share this post


Link to post
Share on other sites

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this