Jump to content
  • Advertisement

Archived

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

Tornado

Making sure a constructor/destructor works

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

Can anyone recommend a way so I can make sure that my constructors and destructors actually work? (They get executed and they do they stuff). I want to make sure there''s no memory leaks. Thanks for your help

Share this post


Link to post
Share on other sites
Advertisement
The easiest way is to just but a breakmark in. Or, if you''re assigning memory, (which it sounds like) you could have a global that you add one to each time a constructor fires, and subtranct one from each time the destructor fires. In the end, it should equal zero.

E:cb woof!

Share this post


Link to post
Share on other sites
Use a static member and just increment for every constructor and decrement for every constructor. Put this at the bttom of each.

Share this post


Link to post
Share on other sites
quote:
Original post by dog135

Or, if you''re assigning memory, (which it sounds like) you could have a global that you add one to each time a constructor fires, and subtranct one from each time the destructor fires.


Quick point: rather than a global, it should really be a static class member, to keep things uncluttered. It will work the same way.

Share this post


Link to post
Share on other sites
Thanks for your help guys!
But if I use a static member (Or a global, doesn''t really matter), How will I know it''s value when the app finishes?
I can''t debug because I''m using full screen.



The road to success is always under construction

Share this post


Link to post
Share on other sites
Tornado, you really should allow your game/app to work in windowed mode, for the lone sake of debugging purposes. It''s not very much more code to do this, and (depending on the size of your program) it will save you tremendous amounts of debugging time.

Also, you might want to consider creating a memory manager that keeps track of all new/deletes and print out the results to the debug window/a file. Of course, doing either (or both) of these takes time to setup, but it''s a one time thing and will save you tons of time in the long run.

I''ve recently implemented a memory manager into my engine, and right away found 3 memory leaks that I never knew about.

Share this post


Link to post
Share on other sites
If I can''t get to and output screen, I like creating a log file in the directory. It can be really simple to do. Just log everything that you would normally "printf" to the file.

Share this post


Link to post
Share on other sites
Houdini: The reason my app/game is fullscreen and not window is the time to setup a windowed app.
I have to calc the position of the window, watch WM_SIZE and other stuff like that.

Stoffel: I already use a debug file, but thanks for the suggestion

Thanks for your help everyone



The road to success is always under construction

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!