C++ - std::sort with a non-static compare method

Usually when you want to sort a std::vector or another container thats holds objects of a custom datatype, you just write a compare function that takes two such objects, does something to find out if one is less than the other, and returns true if it is. Then you pass the address of this function to std::sort and voila.

C++ - Discovering Memory Leaks

If you are working on a serious project, you will propably use a sophisticated memory manager which will also discover memory leaks (along with their exact position in the code), but if you just want to do a quick test in a small program, there is an easy way to let the debugger check for memory leaks:
- Include crtdbg.h in your project (this file is included in the Microsoft Platform SDK)
- At the beginning of main() or WinMain () put this code:

int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
flag |= _CRTDBG_LEAK_CHECK_DF; 
_CrtSetDbgFlag(flag);
This works in Visual C++ ( i don't know about other compilers though ) and, if you run the programm in debug mode, it will report memory leaks in the debug output window ("Immediate Window" in the latest Visual Studio version).

C++ - Bitmap Tutorial: Loading and Saving Bitmaps


1. Introduction

The windows bitmap file format (.bmp) is the most widely used image file format on windows (next to .jpg), and there are many occasions a program or game has to be able to load or save bitmaps ( raytracers and other non-realtime renderers should be able to save their output in .bmp format, games might have to load them as textures etc. ).
Unfortunately .bmp files are not as straightforward as for example .png image files and provide quite a problem for newbies since it's not that easy to figure out how to use them when without a library or API.

Two notes before we start:
1) In this tutorial we're dealing with 24 bit bmps only. But it shouldn't be hard to change the code to support other formats.
2) For clarity's sake i'm only showing the code important to the task at hand, with only minimal error checking. If you want to use this code in a real program, you should add some exception handling.

C# - Non-blocking Per-Pixel Painting in Windows Forms

WinForms gives us the PictureBox control, into which we can easily load images of different formats, have them scaled for us, etc.
But, unfortunately, PictureBox gives us no obvious way to paint it ourself via some SetPixel method.
In this article i will thus show you how to implement your own SetPixel method. As you will know, when you directly execute a long-running function, the user interface will be unresponsive (you won't be able to move the window, or click anything on it) until the function has finished running. When painting something, your paint method might be very long running (for example if you do raytracing), so we will do our painting in a background thread. This will only add a few lines of code, but keep the application running smooth.
Also, since there are different ways to achieve our goals, i will split this article up into two parts, showing you different methods of how to achieve the same effect.

For the rest of this article, i assume that we have a Windows Forms project, and that the form contains a PictureBox named pictureBox1, and a Button (named button1), which will start our test-rendering.