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 theContinue reading “Modernizing Raytracing In A Weekend”

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 canContinue reading “CreateCertificateContext Failed”

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 =Continue reading “Avoid Default Clause in Switch Case for Enum”

Private Inheritance

In private inheritance, the base class public access members are still public access in the derived class. Therefore the derived class still can call the base class functions and access its public data. But the user who instantiates the derived class, cannot access the public member of the base class, hence private inheritance. Public inheritanceContinue reading “Private Inheritance”

Digitally Signing Without Worrying About Cert Expiry

If you want your executable’s signature to be still valid after certificate validity period, you have to digitally sign it with a timestamp from one of the timestamp websites with /tr switch before its expiry. In my case, I choose timestamp.digicert.com. This command is for Windows only. signtool.exe sign /tr http://timestamp.digicert.com /f Cert.pfx /p passwordContinue reading “Digitally Signing Without Worrying About Cert Expiry”

Size of a Empty Class with Virtual Function?

What is the size of the below class? struct MyClass { virtual ~MyClass(); }; The answer is size of a pointer(4 bytes or 8 bytes depending on the platform). That pointer is a vptr to vtbl of virtual functions. That being said, it is not a good idea to initialize a class consisting of PODContinue reading “Size of a Empty Class with Virtual Function?”

Avoid False Sharing With C++11 alignas Keyword

When two threads are frequently accessing and updating the 2 different but independent variables on the same cacheline, cache thrashing occurs as a result because when the thread updates its variable, the thread on another CPU core has its cacheline invalidated and have to fetch from the main memory again even though it is notContinue reading “Avoid False Sharing With C++11 alignas Keyword”

Making HTTP REST Request in C++ With WinHTTP

WinHTTP Wrapper The example code is hosted at Github. The WinHTTP Wrapper consists of one main class that is HttpRequest class. In its constructor, the following parameters: user_agent, proxy_username, proxy_password, server_username and server_password are optional. When accessing the website through a proxy that needs logon, pass in the proxy_username, proxy_password to the constructor. Sometimes, theContinue reading “Making HTTP REST Request in C++ With WinHTTP”