Jump to content
  • Advertisement
Sign in to follow this  
SuperNerd

new keyword "double booking"

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

In the project I am currently working I had an intersting problem with creating new objects. I would create one object (a graphical object) and later created another object (had nothing to do with graphics) and the second object was created with the same memory adress as the first object and so when the program goes to draw the first object it has an error because it was ovewritten with the second was allocated. I found a detour around this error but did not fix it directly. So I don't need a solution but just want to know why the new keyword would create two objects in the same spot in the memory.

Share this post


Link to post
Share on other sites
Advertisement
It wouldn't, unless you did something wrong. Things you may have done wrong:

1. Deleted the memory and not realized it. If you have classes which hold pointers, and you don't know what the expression "rule of three" means, this is probably your problem.

2. Corrupted the heap. Double-freeing pointers, freeing arrays with delete instead of delete[], writing out of bounds of an array, that sort of thing. Note that heap corruption may be caused by a completely different part of the program than the part where you notice the problem.

3. Something else entirely. The point is, new does not do this in a properly written program.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
It wouldn't, unless you did something wrong. Things you may have done wrong:

1. Deleted the memory and not realized it. If you have classes which hold pointers, and you don't know what the expression "rule of three" means, this is probably your problem.

2. Corrupted the heap. Double-freeing pointers, freeing arrays with delete instead of delete[], writing out of bounds of an array, that sort of thing. Note that heap corruption may be caused by a completely different part of the program than the part where you notice the problem.

3. Something else entirely. The point is, new does not do this in a properly written program.

As a moderator and someone one who knows what the "rule of three" is, you should have associated a link with that [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by Alpha_ProgDes
As a moderator and someone one who knows what the "rule of three" is, you should have associated a link with that [smile]

I was giving him the benefit of the doubt. If he's a true super-nerd, he will have opened a tab to Google before he even read the period at the end of my sentence. [grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!