+ 1

The brain is leaking

What are simple rules to have efficient memory in your code?

26th Mar 2017, 6:18 AM
Dimas Fajar
Dimas Fajar - avatar
2 odpowiedzi
+ 6
Sleep in times! (But I still don't have any memory with code -_-)
26th Mar 2017, 6:23 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 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.
26th Mar 2017, 6:23 AM
Squidy
Squidy - avatar