1

I´m using SDL and OpenGL together.

I would like to create my own memory manager, just to rewrite the NEW and DELETE commands to add my memory reservation counter and memory reserved counter to keep more information about what´s going on with my leaks.

But as soon as i overwrite New, i get many errors concerning SDL and MinGW libraries that i´m using, just because i did that, their new are also rewritten, but i just want it for my OWN classes, not to affect those, but i include SDL in many other places in my project.

I also used a class a friend gave me that worked for him, but he just used C++ and OpenGL alone and it worked for him...

What happens here? how do people get to do this so often , and recommend to do this everytime? is it true? Should i do it everytime i can?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Darkgaze
  • 2,280
  • 6
  • 36
  • 59
  • 2
    You don't need to overwrite new, just don't manage memory manually. Use automatic variables first, and for those 0.05% cases when you need to allocate from the free store, use RAII and smart pointers. – Cat Plus Plus Mar 09 '12 at 20:31
  • 2
    The better idea is to avoid the leaks altogether (hint: [don't use `new` and `delete` explicitly](http://stackoverflow.com/questions/8839943/why-does-the-use-of-new-cause-memory-leaks-in-c/8840302#8840302)). Then you don't need to track any info. – R. Martinho Fernandes Mar 09 '12 at 20:31
  • Use smart pointers, please don't bother implementing your own memory system unless you have a real need to. – 111111 Mar 09 '12 at 20:34
  • Oh Super great, thanks a lot. mmm. I don´t know which kind of pointer to use... smart pointers as Martinho said, it´s kind of deprecated... why?... or shared pointer?: Well. i guess that will be in my list of TO-Dos this week. The reason i´m telling you this is because i´m just frustrated while getting SIGSEGV in one weird spot ,just creating a new object of a simple type... – Darkgaze Mar 09 '12 at 20:49
  • `auto_ptr` is deprecated and should be avoided. Prefer stack allocated variables first, otherwise use `unique_ptr` if you can, otherwise use `shared_ptr`. – bames53 Mar 09 '12 at 21:05

0 Answers0