Performance Optimization
I recently taught an introductory course on Performance Optimization. Here are the slides, without the examples:
I recently taught an introductory course on Performance Optimization. Here are the slides, without the examples:
While it is simple to overload methods in C++, the preprocessor doesn’t work the same way. To define overloaded methods in the preprocessor, we need to define a method for each number of arguments we want to overload. Option 1: https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments However, this method is not the most portable, and sometimes doesn’t work with MSVC, so a better approach is using the solution from rextester ONP80107. Option 2: However, this solution doesn’t work out of the box on Windows, as…
When working with STL containers, smart pointers, and boost signals, it is nice to debug directly into your own code without making side trips into container internals. These configs also provide custom object views which make debugging easier in MSVC. To Use You need to reference these files from your project or copy them into <user>\Documents\Visual Studio ####\Visualizers. If you copy them, you must copy the files directly, VS will not recognize any files in subfolders. VS will usually detect…
Some code, including direct UI updates, needs to run directly on the main application thread. When application code becomes increasingly parallelized, we need a simple, easy pattern to invoke back to the main thread which can be used directly across our applications. The standard way to invoke in MFC would be to create a new WM_USER message and handler for every method which needs to be invoked. This works, but gets very clunky when creating a large number of invokes….
When dealing with inheritance, it is possible that the destructors for our objects may never be called if the class has virtual functions, but the base class has a non-virtual destructor. This leads to our derived classes being inadvertently leaky as we leak any memory allocated within the derived class. A detailed description of this bug is available in a Microsoft DevBlog writeup available at: C4265, Part 1 C4265, Part 2 Since this error is not always easy to detect…
While the Pimpl pattern is commonly used to hide implementation and private methods and variables from public interfaces, the common implementations often require a large amount of boilerplate code. This can make it hard to introduce this pattern into a large existing class. If we use bi-directional friend references with the private implementation, we can easily add a small private implementation into an existing class, allowing for better design patterns and performance optimizations to be gently introduced into existing code….
If a query is running really slowly in SQLite immediately after you have performed a large number of inserts, the query optimizer may be out of sync. If you run the ANALYZE command, SQLite calculate a bunch of statistics about your tables which the query analyzer can then use to optimize further queries. It can be an expensive command to run, but you can more than make up for it with improved query performance afterwards. If you want to check…
When working with custom data structures, the debugger can show too much information layered through how you’ve constructed it. To make it easier to debug, you can create a custom visualizer which will present only the information you want, to make it easier to debug. Here’s an example of a custom *.natvis file: Let’s look at a few elements here: If you’re using a previous version of Visual Studio, you’ll need to modify your autoexp.dat file to achieve the same…
Recently I have invented several algorithms to extract more detail from Reflectance Transformation Imaging (RTI) images. Here is a sneak peek of the detail these algorithms can extract: RTI Comparison 1: Missorium of Aspar [L] Default [C] Specular Enhancement [R] New Accelerative Enhancement RTI Comparison 2: Lead Tablet [L] Default [C] New Specular Mesh Enhancement [R] New Normals Visualization
When starting external executables from C++ code, if we start them using SHELLEXECUTEINFO on Windows 10, we cannot maintain a process handle across symlinks like we can on Windows 8. Starting the process using: We should have a value for execInfo.hProcess for the executable the symlink points to as we do in Windows 8. On Windows 10, the executable will start but the process link is not established. Therefore, it will not be possible to read data back from or…