Running VC++ Executable on User Machine Without its DLLs

Since this question is asked on CodeProject today, I'll answer it here. To deploy without having to install the Visual C++ DLLs, the program has to be linked statically. Linking to C runtime statically: Right-click on your project in the Solution Explorer and select Properties and go to C/C++ -> Code Generation. Select Multithreaded (/MT) …

Floating-Point Article Win January Prize

My floating-point article won the best article prize for the articles posted in month of January 2020. The prize is a priceless CodeProject mug(above picture) which is just delivered to my house. The impetus to writing this article started with a rule enshrined in the company wiki that "all multiplications must be converted to divisions …

Copy-On-Write Base Class Template

This tip presents a really simple Copy-On-Write(COW) class template (to be used as a base class) to ease developer effort to implement COW class. Copy-On-Write as its name implies, is a technique to duplicate(copy) shared resource upon write: the only exception to this write operation is when there is only one existing copy and not …

Optimization Turns Out to Be Pessimization!

Benchmark is hosted at Github I have doing this optimization in my hobby OpenGL projects for years. My only sin is I did not measure their performance. I just assumed the one with less operation must be the faster one. Whenever a programmer wants to do get a fractional value of a maximum integer value, …

C++17: codecvt_utf8 is deprecated

Last week, I got this compilation error after upgrading my Visual C++ project to C++17 for using codecvt_utf8 to convert UTF-8 string back and fro wchar_t string. error C4996: 'std::codecvt_utf8<wchar_t,1114111,0>': warning STL4017: std::wbuffer_convert, std::wstring_convert, and the <codecvt> header (containing std::codecvt_mode, std::codecvt_utf8, std::codecvt_utf16, and std::codecvt_utf8_utf16) are deprecated in C++17. (The std::codecvt class template is NOT deprecated.) …

Real Case of Premature Micro-Optimization

The benchmark is hosted at Github I discovered a real case of premature micro-optimization when you don't measure. You know it is pretty bad when you read premature and micro on the same sentence. On the page 44 of Optimizing C++ ebook by Agner Fog, it is written ... In some cases it is possible …

Intel Should Implement Conditional SIMD

Auto-vectorizer can be a great help in vectorizing simple instructions with SIMD instruction calls. int a[COUNT]; int b[COUNT]; int c[COUNT]; for(int i=0; i<COUNT; ++i) { a[i] = b[i] + c[i]; } But a simple conditional check is enough to break the auto-vectorizer. for(int i=0; i<COUNT; ++i) { // a conditional check breaks the auto-vectorizer if(b[i] …

C++: Quick and Dirty Log Extraction and Replay

New Text Stream library is hosted at Github. Log Extraction Hackers can stay infiltrated and undetected up to 200 days! Nowadays, hackers do not even bother to cover their tracks because most logs are not checked for unusual activities. This tip-trick is to help to change all that with the New Text Stream library. Unfortunately, …

C++17: Benchmark of Singular Min/Max and Iterator Versions

The benchmark code is hosted at GitHub. In this tip, we'll benchmark native operator with singular min()/max() and iterator versions like min_element()/max_element(). Lastly, we benchmark the combined operations with minmax_element(). This is the benchmark code. const size_t MAX_LOOP = (argc == 2) ? atoi(argv[1]) : 1000; using int_type = uint64_t; std::vector vec(1000000); std::iota(vec.begin(), vec.end(), 1); …

C#: Never Test For NaN With Equality Test

Let's write a simple program to test. To get a NaN, we do a 0/0 and store it in num. First of all, the divisor has to be a float-point type because DivideByZeroException shall be thrown for integer or decimal zero divisor. Note: Non-zero number divided by zero (float) gives an infinity number. In our …