We’ve covered all the features in the C++ language! Still, C# has some features that are missing from C++. Today we’ll look at those and explore some alternatives to fill these gaps.
Posts Tagged fixed
Fixed-point types save memory compared to floating-point types, but can they also improve performance? Today’s article finds out!
Floating-point math is fast these days, but fixed-point still has a purpose: we can use it to store real numbers in less than 32 bits. Saving a measly 16 or 24 bits off a float
might not sound appealing, but cutting the data size in half or quarter often does when multiplied across large amounts of real numbers. We can shrink downloads, improve load times, save memory, and fit more into the CPU’s data caches. So today we’ll look at storing numbers in fixed-point formats and see how easy it can be to shrink our data!
Continuing the series, today we’ll dive into local functions, fixed
-size buffers, fixed
blocks on arbitrary types with GetPinnableReference
, and stackalloc
initializers to see how they’re all implemented in C++ and what assembly code ends up actually running on the CPU.
C# has some powerful features like fixed
-size buffers, pointers, and unmanaged local variable arrays courtesy of stackalloc
. These are deemed “unsafe” since they all deal with unmanaged memory. We should know what we’re ultimately instructing the CPU to execute when we use these features, so today we’ll take a look at the C++ output from IL2CPP and the assembly output from the C++ compiler to find out just that.
Last week’s article compared the performance of arrays with List<T>
and found List
lacking. This week we’ll optimize both List
and array to maximize performance regardless of which you choose to use.
The series is nearing an end! In today’s article we’ll cover so-called “unsafe” code that gives you unprecedented access to system memory. You can use this to optimize your app or integrate with native (e.g. C, C++) code and APIs. Read on to learn more about this powerful C# tool!