Reputation: 3055
I´m reading C# 5.0 in a Nutshell (O'Reilly) and in the first chapter there is a section that talks about Memory Management. This sections explains about the the unnecessary usage of pointers in C#, because it eliminates the problem of incorrect pointers found in other languages like C++. Finally it mentions the critical usage of pointers in performance-critical hotspots.
Then, what is a performance-critical hotspot and its purpose?
Thanks in advance for your help.
Upvotes: 0
Views: 112
Reputation: 124790
A "performance critical hotspot" refers to a piece of code which is a performance bottleneck. This could be many things, but a good example of this is image processing.
Let's say I have a rather large bitmap and I need to perform some operation on each pixel. This is going to be a loop with many iterations and perhaps a lot going on. Saving a bit of CPU and/or IO time during each iteration of this loop (this "hotspot") will result in a large overall performance gain.
So, GetPixel
and SetPixel
are out the window. They're slow and, from experience, I know they will not perform well on large images. In this case I can use LockBits
to pin the image to its current memory location and obtain a pointer to the raw image bits.
This sort of traversal will result in far faster code and I have now optimized a "performance critical hotspot"
Upvotes: 5