C++14/20 Heterogeneous Lookup Benchmark

Download the benchmark code on GitHub. C++14 introduced ordered transparency lookup which enables const char* and string_view lookup without string instantiation on map/set objects. C++20 introduced unordered transparency lookup that allows to do same thing with unordered_map/unordered_set. We are officially in 2020 but as of writing time, the C++20 Standard is yet to be ratifiedContinue reading “C++14/20 Heterogeneous Lookup Benchmark”

Succinct Guide to Floating-Point Format For C++ and C# Programmers

Floating-Point Dissector is available for download at GitHub. Table of Contents Introduction Floating-Point Dissector Common Misconceptions Floating-Point Conversion to Integer 32-Bit Floating-Point Format Zero Subnormal (Underflow) Subnormal are much slower on Intel processor Infinity (Overflow) Not a Number Summary Chart Floating-Point Exception Equality Test Other Types References Introduction The IEEE 754 standard for floating-point formatContinue reading “Succinct Guide to Floating-Point Format For C++ and C# Programmers”

Lee Algorithm Mazesolver in Direct2D

Table of Contents Introduction Lee Algorithm for Mazesolving Important Notes Direct2D Code References History Introduction In 1999, my team won Obstacle Avoidance Robot(OAR) first prize in the Singapore Robotics Games(SRG). That was 20 years ago. I do not have a photo of OAR, but it looks very much like micromouse. The micromouse maze is constructedContinue reading “Lee Algorithm Mazesolver in Direct2D”

C# 7: ref returns and locals

Table of Contents Introduction ref-return on Value Member Benchmark Conclusion Reference History Introduction C# 7 introduced ref-local and ref-return functionality to allow safe direct-memory access to value variables. Before C# 7, we could do it in an unsafe code but now is available to access in a safe way. This is an example of ref-localContinue reading “C# 7: ref returns and locals”

Bring Your C++ OpenGL Code to the Web

Table of Contents Introduction Render Function Setting up OpenGL with SDL2 Setting up OpenGL with Emscripten OpenGL Shader Precision Inline your Shader Code Load Asset Introduction Prior to reading this article, that is if you have not setup your Emscripten, you have to read this article: Bring Your C++ Code to the Web. Let meContinue reading “Bring Your C++ OpenGL Code to the Web”

C++: Size Matters in Platform Compatibility

Introduction For file storage and data communication to work interoperably, the width of datatype must stay invariant across platforms. This tip discusses the pitfalls of platform-dependent data width and their solution. Endianess, deserving a tip of its own, is not covered here. time_t time_t stores the number of seconds since 1st January 1970. It isContinue reading “C++: Size Matters in Platform Compatibility”

Bring Your Animations to H264/HEVC Video

  Table of Contents Introduction Red Video One JPEG Video Two JPEG Video Text Animation Video Introduction Last year, I introduced a single header windows-based software-based video encoder for OpenGL that works on Windows 7 and above. See the above video demo! I have decoupled it from the OpenGL thread and make it simpler toContinue reading “Bring Your Animations to H264/HEVC Video”

What Web Developers Need to Know About Content Security Policy

Introduction Content Security Policy (CSP) is a computer security standard introduced by the World Wide Web Consortium (W3C) to prevent cross-site scripting (XSS) and clickjacking attacks. Explained simply, CSP is a whitelist of origins of content that is allowed to load or execute on a webpage. We’ll look at the three versions of CSP andContinue reading “What Web Developers Need to Know About Content Security Policy”

Bring Your C++ Code to the Web

  Table of Contents Introduction Installing Windows Subsystem For Linux Installing Emscripten Hello World Programs Calling JavaScript Code from C/C++ Calling C/C++ code from JavaScript Cross Platform Introduction WebAssembly’s predecessor, asm.js converts C/C++, Rust code into a low level JavaScript to run on the web browser. The unveiling of WebAssembly on March 2017 has enabledContinue reading “Bring Your C++ Code to the Web”

C++23: fullptr to replace nullptr

Coming in C++ 2023, detailed in the AF0401 proposal, fullptr_t is fully recommended as the invalid pointer type to replace current nullptr_t which first standardized in C++11. nullptr is defined as a pointer value with all its bits set to zeroes while fullptr has its bits set to ones (the address of the last addressableContinue reading “C++23: fullptr to replace nullptr”