Reaching the end of memory!

Reaching the end of memory!

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Reaching the end of memory!

Post by krogothe »

It seems that my AI is using up all its memory when im calculating huge map arrays (size of a metal map), giving me a load of errors!
The problem itself doesnt seem to be the size of the arrays but when i use a for loop for each element of the array more than 50+ times i get an error saying cant read memory from 0xfffffffffffff (obviously ran out of memory!)
Each time the loop is run a few elements are changed, but why the hell is it taking up all the memory? (copies of the elements being created maybe?)
its driving me nuts :evil:
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

The chances are that you are doing something wrong, not just gradually allocating all memory. If you were, the application would first slow down and fill the HD with cached virtual memory... you usually don't get NULL from the new operator.

Somewhere you must have misused a pointer and stored -1 (0xffffffff) into it..
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

but the error only occurs when i run the loops over X times...
I run 100-1000 loops per pixel on the map, its a shitload of loops, many many millions of them...
is there a way to clear the memory used after each iteration? (besides the array)

heres the code in question (a metal handler):

Code: Select all


	for (int a = 0; a != 20; a++)
	{
		TempMetal = 0;
		for (int i = 0; i != TotalCells; i++)
		{			
			if (MexArrayB[i] > TempMetal)
			{
				TempMetal = MexArrayB[i];
				coordx = i%MetalMapWidth;
				coordy = i/MetalMapWidth;
			}
		}
		
	
		if (TempMetal)
		{
			for (int myx = coordx - XtractorRadius; myx != coordx + XtractorRadius; myx++)
			{
				if (myx >= 0 && myx <= MetalMapWidth)
				{
					for (int myy = coordy - XtractorRadius; myy != coordy + XtractorRadius; myy++)
					{
						if (myy >= 0 && myy <= MetalMapHeight && ((coordx - myx)*(coordx - myx) + (coordy - myy)*(coordy - myy)) <= XtractorRadius*XtractorRadius)
						{
							MexArrayB[myy * MetalMapWidth + myx] = 0;
						}
					}
				}
			}
		}
		MexArrayA[coordy * MetalMapWidth + coordx] = TempMetal;
	}
It seems to me that the program is spawning so many myx and myys that it takes up all the memory...
Last edited by krogothe on 03 Dec 2005, 21:07, edited 3 times in total.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Could you post some code? it will be easier to understand what is happening...
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

^^^
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Ok well you're not allocating any heap memory, so it's impossible to fill up the memory.

You're probably not bounds-checking correctly:

Code: Select all

   if (myx >= 0 && myx <= MetalMapWidth) 
should be
    if (myx >= 0 && myx < MetalMapWidth) 

and 

   myy >= 0 && myy <= MetalMapHeight
should be
   myy >= 0 && myy < MetalMapHeight
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

wooooo i fixed it!
it was both what zaph said and bad programming that caused it!
thanks
Post Reply

Return to “AI”