If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: size of structure

thank you all , so it is ok to force structure alignment via pragma pack(1) , so the structure perfectly aligns with binary file header , any down side at all.

Of course, there is a downside. Otherwise, why do you think the default option would be to waste memory?

If you need to read a struct from a binary input, then read the elements one by one. Packing may give you a small performance gain on reading/writing (which is slow anyway), but cost performance on other operations (which are typically not slow).

Also, you should carefully consider whether the binary representation of a type will always be the same. The posts above show that this is not the case for different compilers / platforms. Unless you can exclude such cases, I wouldn't advice using binary files.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: size of structure

Be careful with pack(1) or __align; A lot of processors do not allow mis-aligned ints. ARM, Blackfin, SHARC, and several others will crash if you don't have the BYTE, WORD, or DWORD on a 16 bit boundary.

Re: size of structure

I'm confused why you're writing your own bitmap loader anyway. There are tons of them out there for both loading standard bitmaps and windows bitmaps. They will do memory alignment, row padding, header loading and validating all for you. Bitmaps are weird. For instance, if the header says that the bitmap is 3 bytes per pixel, and it's 10 pixels wide, how many bytes is one row of the bitmap in the file? I'll give you a hint, it's not 30.

The only guarantees with respect to size in bytes, yes. However, it is not the only guarantee when we include range. For a standard conforming implementation on which sizeof(char) == sizeof(long), it implies that the range of char would be at least [-2147483647, 2147483647] if it were signed, or [0, 4294967295] if it were unsigned. I find that rather unlikely, though certainly possible.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.