@SpriggsySpriggs — what you’re running into is Data Alignment/Packing. Here’s a pretty good write up on what’s going on, down at Chapter 17:
https://www.viva64.com/en/a/0004/#ID1C7DC5438C
Processors work more efficiently when they deal with data aligned properly. As a rule the 32-bit data item must be aligned at the border multiple of 4 bytes, and the 64-bit item at the border multiple of 8 bytes. An attempt to work with unaligned data on IA-64 (Itanium) processors will cause an exception as shown in the following example,.
#pragma pack (1) // Also set by key /Zp in MSVC
struct AlignSample {
unsigned size;
void *pointer;
} object;
void foo(void *p) {
object.pointer = p; // Alignment fault
}
If you have to work with unaligned data on Itanium you should tell this to the compiler. For example, you may use a special macro UNALIGNED:
#pragma pack (1) // Also set by key /Zp in MSVC
struct AlignSample {
unsigned size;
void *pointer;
} object;
void foo(void *p) {
*(UNALIGNED void *)&object.pointer = p; //Very slow
}
This solution is not efficient, because the access to the unaligned data will be several times slower. A better result may be achieved if you arrange up to 32-bit, 16-bit and 8-bit items in 64-bit data items.
On the x64 architecture during the access to unaligned data, an exception does not occur, but you should avoid them also. Firstly, because of the essential slowdown of the access to this data, and secondly, because of a high probability of porting the program on the IA-64 platform in the future.
Basically, you align your data on 8-byte breakpoints, rather than 4.
The only point where I get lost in these conversions is how we determine those breakpoints.
dx AS LONG
dy AS LONG
dwSize AS LONG
Now, with the above, would we have EVERY long padded to 8 bytes? Or would the first two variables (dx and dy) be counted together as 8-bytes, and fit the breakpoint? Or do we padd the first and join the last two??
I *still* haven’t sat down and sorted out where the BLEEP we’re required to have those 8-byte breakpoints in data types. All I can do is sit down in front of a keyboard, and furiously attempt to change first one and then the other, until I finally find a combo that works.