Archived

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

Zoot

Strange memory...

Recommended Posts

HEAP[Demo.exe]: HEAP: Free Heap block 4c66250 modified at 4c66310 after it was freed Anyone know what it means? I only get this message when i load big maps in my engine.. it works perfectly with small maps.. I am useing new and delete...

Share this post


Link to post
Share on other sites
do what he said, it only works with small maps because u''re lucky or something. use a memory manager like MMGR (http://www.fluidstudios.com/publications.html) to make debugging memory leaks easier. if your program starts crashing often when u use it, that''s good, because it detected something bad, read the log files and fix it.

---
shurcool
wwdev

Share this post


Link to post
Share on other sites
Maybe the problem doesn''t manifest itself with small maps... bugs can be weird and once they occur and the program goes into an undefined state, anything can happen! I would definitely recommend the nulling of the pointers after the delete, that should cause the program to die at the point where the freed pointer is dereferenced, if you run through the debugger you should be able to see the exact line that it happens on.

The only other thing I can think of is that you could be using a 16-bit compiler and you are trying to allocate more than 64K at once.

... thought of a few more possibles...

Have you checked that the allocations actually succeed? Does new throw an exception or return NULL if it fails?

I would certainly recommend running the code through a debugger and mabe putting breakpoints on every line that you call delete... to check everything is working as you expect.

Share this post


Link to post
Share on other sites
I tested the memory manger but it didn´t work so well with ifstream..

But i plaied some and now i get this error instead:

memory check error at 0x03ECBF10 = 0xF8, should be 0xFD.
memory check error at 0x03ECBF11 = 0xE4, should be 0xFD.
memory check error at 0x03ECBF12 = 0xA8, should be 0xFD.
memory check error at 0x03ECBF13 = 0x03, should be 0xFD.

[edited by - Zoot on August 14, 2002 2:44:52 PM]

Share this post


Link to post
Share on other sites
It means you''re writing to memory you shouldn''t. Paradigm Shifter''s suggestions sound reasonable. Or maybe you are writing past the boundaries of an array.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
quote:
Original post by shurcool
do what he said, it only works with small maps because u're lucky or something. use a memory manager like MMGR (http://www.fluidstudios.com/publications.html) to make debugging memory leaks easier. if your program starts crashing often when u use it, that's good, because it detected something bad, read the log files and fix it.

---
shurcool
wwdev



Have any idea of how i can get it to work with ifstream?

This works but gives memory leaks:

ifstream *file = new ifstream(filename, ios::in );
file->close();

Any ideas?

[edited by - Zoot on August 14, 2002 9:53:26 PM]

Share this post


Link to post
Share on other sites
Well, you''re not freeing the ifstream, are you? "delete file;".
But why bother allocating it like that? Why not just:

ifstream file(filename, ios::in);

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
If you''re using anything that looks like "delete this;" take that out first. C++ doesn''t like you doing that, because then it calls the destructor from whatever class method you''re in, then RETURNS TO THE METHOD IN THE NOW DELETED CLASS. That is Bad.

Share this post


Link to post
Share on other sites