C++: Difference between revisions

From David's Wiki
No edit summary
No edit summary
Line 5: Line 5:
== Standard Library ==  
== Standard Library ==  
=== Sleep ===
=== Sleep ===
<pre>
<syntaxhighlight lang="C++">
std::this_thread::sleep_for(std::chrono::milliseconds(1));
std::this_thread::sleep_for(std::chrono::milliseconds(1));
</pre>
</syntaxhighlight >


=== Garbage Collection ===
=== Garbage Collection ===

Revision as of 15:56, 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.