4

BitmapData has a property called Reserved, which returns a 32-bit signed integer. Microsoft's documentation says not to use this property. If we shouldn't use it; then why is it there? What exactly is it for?

Gustavo Mori
  • 7,820
  • 3
  • 35
  • 51
bbosak
  • 5,073
  • 7
  • 37
  • 57

3 Answers3

4

Reserved fields and properties can have a variety of uses. One fairly common usage is to allow for the possibility that more sophisticated types of BitmapData may in future need to store some type of information for which the present structure makes no provision. If nobody has used the Reserved field for anything, future implementations could use that field to hold a pointer or handle to another structure containing additional information.

supercat
  • 69,493
  • 7
  • 143
  • 184
  • What's the point in calling the property "Reserved"? Or is it that the name may be changed at a later date, and the field simply exists to make sure there's room in the underlying struct? – JAB Jun 20 '11 at 21:35
  • 1
    If it follows a pattern I've seen before (though not necessarily from Microsoft), there may be a later type BitmapDataEx, which is identical to BitmapData except that the field that used to be "Reserved" will now have some other name (and possibly type). Code which expects a pointer to a BitmapDataEx will work just fine if given a pointer to a BitmapData, provided the Reserved field is left initialized to zero. – supercat Jun 20 '11 at 22:23
  • 1
    ...because they're RESERVED for a future time when it's needed. – ta.speot.is Jun 20 '11 at 22:40
3

Interesting, that's a bug. It is actually an IntPtr, you can tell from the native declaration, GdiPlusImaging.h header file in the SDK (c:\program files\microsoft sdks\windows\v6.0a\include directory for VS2008). The bug doesn't byte because GDI+ creates the instance of it.

Which makes it likely that the field stores a pointer or a handle. I would guess at the memory mapped file object handle. Cheaper to store it in the client state object over having to maintain a dictionary to find it back in the UnlockBits() function. Don't mess with it.

Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371
1

There are a lot of these in Microsoft's older APIs, and they stem from a time when it was common to put space in property sets for future development efforts. They serve the same purpose as a big red button that nobody is supposed to push. Maybe someone will want a button in the future, and then, well, we've already got this one right here!

Paul Sonier
  • 36,435
  • 3
  • 72
  • 113