Archived

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

Allebarde

VC++ problem and Memory

Recommended Posts

Hi! I have again Memory problems : I you remember, I posted a question about a VC++ error that occured when I did a delete CurrentChunck.. In fact using debug I found where exactly the error was: Model3ds.pObject[Model3ds.numOfObjects - 1]; Model3ds.numOfObjects++; //HERE NO PROBLEMS : CurrentChunk is not modified //allocate some memory *( &Model3ds.pObject + (Model3ds.numOfObjects-1)*sizeof(Object3DS) ) = new(Object3DS); //CurrentChunk is not Modified // Initialize the object and all it''s data members memset(&(Model3ds.pObject[Model3ds.numOfObjects - 1]), 0, sizeof(Object3DS)); //HERE PROBLEM: CurrentChunck is modified // Get the name of the object and store it CurrentChunck->bytesRead += SearchString(Model3ds.pObject[Model3ds.numOfObjects - 1].strName); Apparately the problem occurs when I set the memory to 0 with memset.. A friend who''s coding under DOS, has the same problem: Can someone help us? Thanks

Share this post


Link to post
Share on other sites
There''s probably a bug in your code. Especially a line like

*( &Model3ds.pObject + (Model3ds.numOfObjects-1)*sizeof(Object3DS) ) = new(Object3DS);

makes me suspect there''s something wrong.

What type is the Model3ds variable? Do you use it as an array of some sorts? And how is the Object3DS type defined? If it''s a class with (virtual) member functions, it''s a very bad idea to use memset to zero out the memory. Just make a constructor that initialises all members to some initial value if you need such functionality.

Share this post


Link to post
Share on other sites
quote:
Original post by Allebarde
Object3DS is a structure

Ok. Then forget the constructor thing, it''s not needed here.

That still leaves the question about Model3ds. How is it declared? The same holds for CurrentChunk. Without knowing what types these are and how these types are defined, it''s difficult to tell what''s going on!

Share this post


Link to post
Share on other sites