Another tip for C++ developers: Who frees the memory?.
The rule I always had was: The one that allocates it, must also free it.
That way there is no discussion who should clean it up and have memory leaks.
If you do have to transport one memory structure to another location to process it, clone it! You take up more RAM for your application but your code will be more predictable and secure.
Local variables are allocated on the stack. But once in a while as a C++ developer you make a mistake when you move one byte too far.
Normally you should get an access violation, but if 2 memory local allocations are near each other you could corrupt the next variable and you get random errors. The trick is to swap the place of these variables, that could trigger the access violations or other bugs and discover your bug.
3 comments
2 u/roznak 05 Aug 2015 22:22
Another tip for C++ developers: Who frees the memory?.
The rule I always had was: The one that allocates it, must also free it. That way there is no discussion who should clean it up and have memory leaks.
If you do have to transport one memory structure to another location to process it, clone it! You take up more RAM for your application but your code will be more predictable and secure.
1 u/roznak 05 Aug 2015 21:28
Nice.
A tip for those c++ programmers.
Local variables are allocated on the stack. But once in a while as a C++ developer you make a mistake when you move one byte too far.
Normally you should get an access violation, but if 2 memory local allocations are near each other you could corrupt the next variable and you get random errors. The trick is to swap the place of these variables, that could trigger the access violations or other bugs and discover your bug.