+ 1
The brain is leaking
What are simple rules to have efficient memory in your code?
2 Answers
+ 6
Sleep in times!
(But I still don't have any memory with code -_-)
+ 4
⢠Use stack memory where possible. Allocating memory on the heap is very slow in comparison.
⢠Set your pointers to nullptr (or 0, in C) after freeing dynamic memory so you don't wind up with a dangling pointer. (This isn't necessary, but good practice if the pointer isn't immediately popped off of the stack.)
⢠Use the RAII principle to make it easier to make sure that all dynamic memory is freed.