Data Alignment

Data Alignment 는 CPU 에 대해 조금 알고 있어야 합니다. 간단히 이야기 하면 Word 의 data 를 사용할 때는 시작 주소가 2로 나누어서 0으로 떨어지게 정렬되어 있어야 하고 DWORD 값을 사용할 때는 시작 주소가 4로 나누어 0 으로 떨어지게 정열되어 있어야 합니다. 만약 data alignment 가 맞지 않다면 1번 Read 해서 처리할 수 있는 일을 2번 읽어서 처리 해야 합니다. (결국 추가 작업을 하게 되어 성능저하를 가져 옵니다. ) x64 과 ㅌ86  에서는 CPU 에서는 이 동작을 CPU 에서 처리해 주지만 IA64 CPU 에서는 CPU 에서 처리해 주지 않습니다. 추측이지만 x64와 x86은 CISC 구조이고 IA64 는 RISC 구조 이기 때문에 그런게 아닌가 합니다.

아는 분의 블로그에서 확인한 내용으로 IA64 에서 동작하는 32Bit Application 에서는 오류가 발생하지 않는다고 합니다. 이 내용을 확인해 보면 IA64 에서 특정 Process 에 대해서 SetErrorMode() 함수를 SEM_NOALIGNMENTFAULTEXCEPT flag 와 같이 사용하면 Windows 운영체제에서 Data alitnemtn 에 대해서 처리를 해준다는 것 입니다.

 

UINT SetErrorMode(
  UINT uMode
);
Controls whether the system will handle the specified types of serious errors or whether the process will handle them

SEM_NOALIGNMENTFAULTEXCEPT
The system automatically fixes memory alignment faults and makes them invisible to the application. It does this for the calling process and any descendant processes. This feature is only supported by certain processor architectures. For more information, see the Remarks section.
After this value is set for a process, subsequent attempts to clear the value are ignored.