Thread: messing around with bitmaps

  1. #16
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by nonoob View Post
    Seems to be true but there's no point in switching off the pack directive.
    In this specific case, it's probably not a big deal. I'm betting the OP is on an x86 architecture, which supports misaligned reads/writes from memory. Other (typically RISC) architectures, like ARM, are not so friendly to misaligned reads, and the resulting code may be several times slower for accessing misaligned data that results from packing structures (unless you're lucky enough to be able to organize your struct members to be naturally aligned when packed).

  2. #17
    Registered User
    Join Date
    Jan 2012
    Posts
    26
    What if the address was pulled out of the structure declared with malloc() into a void pointer, decremented by two, then assigned to a pointer used for the next member in the structure with that structures data type? I guess that would be a pain though since you would need pointers for each member in the structure that doesn't naturally align, and using the wrong pointer on a member would garble the data block.

  3. #18
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    That would be a giant mess just begging for extra bugs. Besides, after taking the void pointer and incrementing it and assigning or casting it to, say, a uint16_t pointer to dereference, would still result in a misaligned read. It's an assembly/hardware issue you can't just sweep under the rug with nasty pointer ju-ju. There's absolutely nothing wrong with packing structures and having misaligned reads when you have to. It's just that you shouldn't go around packing structs unnecessarily.

  4. #19
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    If developing with the Windows SDK, you should just include Windows.h and use the pre-defined BITMAPFILEHEADER structure. The other structures are all present as well. They are declared with the correct packing.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CWinThread messing itself up
    By LowlyIntern in forum C++ Programming
    Replies: 7
    Last Post: 01-16-2009, 08:08 AM
  2. Messing with folders
    By Probose in forum C++ Programming
    Replies: 2
    Last Post: 09-21-2006, 03:16 PM
  3. Is someone messing with m$ again?
    By exluddite in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-16-2004, 01:56 PM
  4. Messing with Large Integers
    By johnnie2 in forum Windows Programming
    Replies: 3
    Last Post: 11-16-2002, 01:22 PM
  5. Do you think this might be messing up my brain?
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-21-2002, 08:33 AM