by rcp » Sep 6, 2004 @ 9:01am
I just read the article you mentioned and I can't believe that it said to not use malloc(). I've got lots of code that uses it and one game that malloc/frees tons of memory (well over 10mb). None of this has ever caused a problem. No leaks, drips, runs or errors.
For your specific situation, keep the header/palette information apart from the bitmap data. The header shouldn't stored as BITMAPINFOHEADER, but as a more generic structure.. read in BITMAPINFOHEADER and then translate. This is helpful when you start reading bitmaps of other types... such as JPG or TGA. With your header in a generic format and the bitmap data in its own array, your CBitmap class can work for more than one file type. Change your ::LoadDIB(char *filename) to ::FromFile(char *filename) and have that function look at the extension (or similar) to determine the filetype and then call the specific function for that filetype. It sounds like more work, but three years down the road when you are using this class for 10 different formats, you'll be happy you got it right to start! My 'bitmap' class was started in '91 with Win31 and I still use it today. Get these basic classes solid and you can use them for years.
Cheers,
rcp