Deleaker detects resource leaks in StackOverflow answer

Recently, I need to capture the mouse cursor in my homebrew screen capture application, so my search sent me to StackOverflow's Capture screen shot with mouse cursor. Out of curiosity, I ran Deleaker on it and it finds 2 HBITMAP leaks with every capture. My application captures mouse cursor 30 times per second, so the …

Anti-Pattern: Enum as Array Index with No Bound Check

Recently, I encountered program crashes because of unscoped enum as array index pattern once in the workplace and another in an open source library where I added another item in the enum. Evidently, this anti-pattern is very popular among C++ developers. Open source code using Enum as Array Index pattern without bound check in its …

Put sleep() to make more money from HFT. And Lock-free vs Block-free

"Isn't April Fools over?" the very first thought running through your mind after glancing at the title. Rest assured, this is not a trolling post to make a fool out of you. This year's April Fool post is here, in case you missed the once-in-a-lifetime C++ joke of its kind. This article is about slowing …

C++23: -> and :: to be replaced by . operator

In the biggest change to C++ syntax, -> and :: operators are to be replaced by . operator in the upcoming C++23 AF00L proposal. The rationale behind this proposal is there can be no confusion (as to which operator to use). The :: operator is not only used in scope resolution and also as class-to-static_member. …

Modernizing Raytracing In A Weekend

Ray Tracing In A Weekend Repo My Modernized Ray Tracing In A Weekend Repo The improvements I made to the original code: Convert all raw allocation to shared_ptr to prevent memory leaks.Replace non-reentrant rand() with a copy of C++11 random number generator in every thread using thread_local to avoid sharing and locking.Replace the text-based image …

CreateCertificateContext Failed

CertCreateCertificateContext failure can be fixed with first exporting the certificate to DER Encoded Binary X.509 (cer file) manually. std::vector<BYTE> vec; PCCERT_CONTEXT pCertContext = NULL; if (pCertContext = ::CertCreateCertificateContext( PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, vec.data(), vec.size())) { std::cout << "Success!\n"; } else { std::cout << "Failure!\n"; } If one want to forgo the manual export option, CryptQueryObject can …

Avoid Default Clause in Switch Case for Enum

Do not define a default clause for enum in switch statement! Say in future, if another fruit type is added to the enum, default clause shall cause the C++ compiler not to warn you that you have not handled the case for the new fruit. enum class Fruit { Apple, Orange }; Fruit fruit = …