Huge memory leak issues.
Quote:Original post by Fruny
delete[] mesh;
Well, I fixed that particular issue, but I think that the Get/Set routines aren't causing the problem - I'm pretty sure its in the contructor and destructor, since removing anything about Get/Set TerrainCell didn't affect the programs performance - allocating 30,000 doubles (1 Mesh of size 100x100) didn't affect performance visibly, but after creating and, in theory, destroying around 17 of them, my system came to almost a halt, and that is where I wound up using up all the system resources. I'm 100% certain its the destructor's fault.
Quote:Original post by Fruny
delete[] mesh;
You mean like this? Tried it, and it didn't change anything, unfortunately
Mesh::~Mesh(){ for ( unsigned int i = 0; i < MESH_HEIGHT; ++i ) { delete[] mesh; } delete[] mesh;}
OK, I can't find it either, nobody. Actually, thanks alot for the help, Fruny. I tried something interesting: increased the size of MESH_WIDTH and MESH_HEIGHT to 1000 (basically made the size of a Mesh ten times bigger). And guess what: it ran exactly the same as when it was 1/10th the size, petering out after 17 destructor calls. So I guess the destructor is working. And after 17 tries, it slows down considerably, but it doesn't stop. I think if I left it running long enough, it would eventually finish. Anyone ever experianced this?
[EDIT] nevermind - instead it crashed after creating two Meshes, as I would have expected if the Mesh wasn't being created - having 1,000,000 must be no fun for the computer. I think I accidentally didn't do a full build, just compiled the wrong files. Any help, guys?
[EDIT] nevermind - instead it crashed after creating two Meshes, as I would have expected if the Mesh wasn't being created - having 1,000,000 must be no fun for the computer. I think I accidentally didn't do a full build, just compiled the wrong files. Any help, guys?
Quote:Original post by silverphyre673Quote:Original post by Fruny
delete[] mesh;
You mean like this? Tried it, and it didn't change anything, unfortunately
*** Source Snippet Removed ***
no, like this:
Mesh::~Mesh(){ for ( unsigned int i = 0; i < MESH_HEIGHT; ++i ) { delete mesh; // delete single } delete[] mesh; // delete array}
why obfuscate things, I avoid nD dynamic arrays whenever I can
(it usually saves me time somewhere else *cough*debugging*cough*)
you can change it over when you're sure the code works.
struct MeshPointer {
Mesh *p;
};
MeshPointer *meshes;
for each M in meshes
delete M.p;
delete[] meshes;
Is there any particular reason why your storing pointers to TerrainCell instead of TerrainCell, which you have done in both cases with std::vector & C-style dynamic array.
Do you know std::vector separates allocation/deallocation & construction/destruction, so you can do things like allocate a chunk of uninitialized memory and then at a later time incrementally initialize each element (you can do this with C-style dynamic arrays but its low-level code)
Do you know std::vector separates allocation/deallocation & construction/destruction, so you can do things like allocate a chunk of uninitialized memory and then at a later time incrementally initialize each element (you can do this with C-style dynamic arrays but its low-level code)
Quote:Original post by silvermaceQuote:Original post by silverphyre673Quote:Original post by Fruny
delete[] mesh;
You mean like this? Tried it, and it didn't change anything, unfortunately
*** Source Snippet Removed ***
no, like this:
*** Source Snippet Removed ***
why obfuscate things, I avoid nD dynamic arrays whenever I can
(it usually saves me time somewhere else *cough*debugging*cough*)
you can change it over when you're sure the code works.
struct MeshPointer {
Mesh *p;
};
MeshPointer *meshes;
for each M in meshes
delete M.p;
delete[] meshes;
I think I'll try this at home. I hate multidimentional arrays too :)
Not sure if it'll work, and I'm still not sure why the program is using all the resources, but I'll give it a shot.
Jingo: it's not crashing, just using all the system resources (memory).
snk_kid: I want to keep the memory off the stack to increase the amount of memory I can utilize. Tell me if this is false thinking.
Quote:Original post by silverphyre673
snk_kid: I want to keep the memory off the stack to increase the amount of memory I can utilize. Tell me if this is false thinking.
It is. The vector already "keeps the memory off the stack"; the members of vector<T> look something like
int capacity; // how much storage space is allocatedint size; // how much of it actually corresponds to valid elements// possibly a couple other little things I forgotT* storage; // since it's variable, it would be kind of hard to put on the stack!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement