C++: Difference between revisions

From David's Wiki
No edit summary
No edit summary
Line 8: Line 8:
std::this_thread::sleep_for(std::chrono::milliseconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds(1));
</pre>
</pre>
=== Garbage Collection ===
Traditional C++ does not have garbage collection. 
After using `new` to allocate an object, use `delete` to deallocate it. 
You can also use C allocation with `malloc`, `calloc`, `alloca`, and `free`. 
If using C++14, you can use [https://en.cppreference.com/w/cpp/memory/shared_ptr shared pointers] which does have automatic garbage collection.

Revision as of 15:48, 14 August 2019



Standard Library

Sleep

std::this_thread::sleep_for(std::chrono::milliseconds(1));

Garbage Collection

Traditional C++ does not have garbage collection.
After using `new` to allocate an object, use `delete` to deallocate it.
You can also use C allocation with `malloc`, `calloc`, `alloca`, and `free`.
If using C++14, you can use shared pointers which does have automatic garbage collection.