Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

uber_n00b

Bad memory management?

This topic is 5220 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

I really am stumped at this point. After building an octree of well over 2 million polygons, my comp essentially freezes and I have to restart. When I declare temporary pointers I always use the delete function afterwards and clean up memory as much as I can, but is it normal to hit the fan at such a low polycount? BTW my octree is very similar to DigiBen''s COctree class but with a few mods for collision detection and the such. Anyway specs on my comp: 2.8GHz p4 512MB RAM. I did notice about halfway through XP said it had to allocate more virtual memory, but I don''t exactly know what it meant besides my octree was being wasteful. Ideas? I know I''m being vague but maybe if someone asks questions I may answer them to obtain a clearer response.

Share this post


Link to post
Share on other sites
Advertisement
Everything I have to delete is in the form datatype **variable. To delete, I do this:

for(int i = 0; i < (known array size); i++)
{
delete [] variable[i];
}

Is this wrong?

[edited by - uber_n00b on June 4, 2004 11:28:38 PM]

Share this post


Link to post
Share on other sites
Should I? I was just giving an example of how I delete my variables (all in the form datatype ** variable)

Share this post


Link to post
Share on other sites
If you're doing this


datatype ** variable;
variable = new datatype*[known array size];
for(int i = 0; i < (known array size); i++)
{
variable[i] = new datatype;
}



when you delete you will need to do a
delete [] variable;

after your for loop of deletes


edit: it would actually be faster and much more cache friendly if you were to use a 1d array instead

[edited by - DrEvil on June 4, 2004 12:04:17 AM]

Share this post


Link to post
Share on other sites
Alright here is what I get from what you said:


void FunctionName()
{
CPoly **pPoly = new CPoly*(CONST);
for(int i = 0; i < CONST; i++)
pPoly[i] = new CPoly(CONSTB);
//that was the initialize, assume i do other stuff here

for(i = 0; i < CONST; i++)
delete[] pPoly[i];
//I didn't delete it all the way? Uh oh :) Explain DrEvil


}
/*Edit: Unfortunately I do not know how to build an octree

while implementing geomipmapping without creating a 2D array of
polygons, so I am not sure if I could condense it down to 1D
although really I'd like to make it a fractal terrain but then
Octrees get a little weird (maybe if you build the fractal
terrain first then divide it up? Not too sure on the details,
anyway that is for another forum). Anyway, if you have any better ideas on how to convert it to 1D that would be great.
Oh the reason I have it in 2D is that each element in the leftmost subscript defines the level of detail, and the second
subscript is the list of polygons that correspond to that detail level. Inefficient I know.*/



[edited by - uber_n00b on June 4, 2004 12:11:38 AM]

[edited by - uber_n00b on June 4, 2004 12:12:45 AM]

Share this post


Link to post
Share on other sites
2,000,000 x 3 x 32 (assuming your vertices for each triangle are only 32 bytes long):

192,000,000 bytes of memory.

Count on 50-60% of additional memory to be used by the debugger.

That''s just for these functions.

Now, the 1-d array idea works well, if (and only if) you expect to have all of the arrays the same size.

Share this post


Link to post
Share on other sites
what''s happening is that you''re deleting all of the objects of type CPoly* with the loop, but you need another ''delete [] pPoly;'' to get rid of the initial CPoly** you created.

Elijah

Share this post


Link to post
Share on other sites
change:


for(i = 0; i < CONST; i++)
delete[] pPoly[i];


to:


for(i = 0; i < CONST; i++)
delete[] pPoly[i];

delete[] pPoly;


Otherwise, you create a memory leak of 4*CONST bytes. (a pointer is 4 bytes long).

Simple rule of thumb when it comes to memory leaks: You need to have a delete call for EVERY new call you make.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!