Understanding algorithm complexity, specifically Big-O notation, is crucial for analyzing and comparing the efficiency of algorithms. In C++, as in other programming languages, the complexity of an algorithm can significantly impact the performance and scalability of an application. So it’s useful to know how to improve the algorithm complexity. But before that let’s explore the most common algorithm complexities:
Continue reading “7 Tips to improve the C++ algorithms complexity (Big-O)”Tag: c++ performance
Could Herb Sutter’s call to action for C++ safety be acheived soon?
Recently, Herb Sutter wrote an excellent article on C++ safety. He discussed numerous ideas, but I’ll provide a summary of his perspective on what can be done in the medium term to enhance C++ safety.
In C++, by default enforce … | (A) Solution for new/updated code (can require code changes — no link/binary changes) | (B) Solution for existing code (requires recompile only — no manual code changes, no link/binary changes) |
Type safety | Ban all inherently unsafe casts and conversions | Make unsafe casts and conversions with a safe alternative do the safe thing |
Bounds safety | Ban pointer arithmetic Ban unchecked iterator arithmetic | Check in-bounds for all allowed iterator arithmetic Check in-bounds for all subscript operations |
Initialization safety | Require all variables to be initialized (either at declaration, or before first use) | — |
Lifetime safety | Statically diagnose many common pointer/iterator lifetime error cases | Check not-null for all pointer dereferences |
Less undefined behavior | Statically diagnose known UB/bug cases, to error on actual bugs in existing code with just a recompile and zero false positives: Ban mathematically invalid comparison chains (add additional cases from UB Annex review) | Automatically fix known UB/bug cases, to make current bugs in existing code be actually correct with just a recompile and zero false positives: Define mathematically valid comparison chains Default return *this; for C assignment operators that return C& (add additional cases from UB Annex review) |
But what are the current possibilities for achieving this goal?
Continue reading “Could Herb Sutter’s call to action for C++ safety be acheived soon?”Thrashing Impact on C++ Performance: Doxygen Analysis
When the processes running on your machine attempt to allocate more memory than your system has available, the kernel begins to swap memory pages to and from the disk. This is done in order to free up sufficient physical memory to meet the RAM allocation requirements of the requestor.
Excessive use of swapping is called thrashing and is undesirable because it lowers overall system performance, mainly because hard drives are far slower than RAM. Continue reading “Thrashing Impact on C++ Performance: Doxygen Analysis”