#### Archived

This topic is now archived and is closed to further replies.

This topic is 6451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have this structure: struct TERRCOORD { WORD height; BYTE lightIntensity; }; So 3 bytes, right? But it turns out sizeof(TERRCOORD) evaluates to 4. I guess the WORD has to align to an even byte or something... right? In my game, this structure is used like so: DWORD terrainSize = 4000000; // or similar TERRCOORD* terrCoords = new TERRCOORD[ terrainSize ]; I really need to keep this data (height & lightIntensity) to 3 bytes/coordinate. How can I do this? I don''t want to have separate height and lightIntensity arrays, because then I''d have to incrememnt two pointers instead of one when processing the coords.

##### Share on other sites
If you are doing this in windoze w ith VC++ then it pads structures to be aligned on a 32 bit boundry by default. Fool around with the options and see if you can somehow disable padding.

---
www.crazycrackerz.org

##### Share on other sites
In MSVC, you can disable padding as follows:

  // Byte-align, other values are 2, 4, 8, 16.#pragma pack(1)typedef struct{ . . . };// Use default padding.#pragma pack

But usually, you want to leave padding enabled. If a non-naturally sized piece of data is accessed, the processor will do multiple aligned memory accesses to assemble the data.

Edited by - mhkrause on June 26, 2000 10:16:43 PM