Apple Darwin User Manual Page 54

  • Download
  • Add to my manuals
  • Print
  • Page
    / 68
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 53
When transitioning your application, kernel extension, or other code to 64-bit, you may notice a performance
decrease, depending on your code. While in some cases this is caused by simply moving more data around,
in many cases, it is caused by fairly minor data structure layout issues and other easily corrected issues. This
chapter briefly describes some of these issues and explains how to correct them.
Data Structure Bloat
Software compiled as a 64-bit executable is likely to use more memory than its 32-bit counterpart because of
the increased size of data and pointers. However, many of these increases are exacerbated by changes in data
alignment. Such increases, which can affect performance, are easily avoided.
As noted in Data Type and Alignment Tips (page 19), data structure alignment is different for 64-bit executables.
The following snippet shows a small data structure:
struct mystruct {
char member_one[4];
void *member_two;
int member_three;
void *member_four;
int member_five;
}
In a 32-bit executable, this data structure takes 20 bytes. The pointers are 4 bytes long, and are aligned on a
4-byte boundary. If the structure is allocated dynamically, even though you only request 20 bytes, the memory
allocator will actually assign it a memory region that is 32 bytes long (the nearest power-of-2 boundary).
In a 64-bit executable, this data structure bloats to a whopping 36 bytes and is padded to 40 bytes (because
it must be 8-byte-aligned), which means that if allocated dynamically, it occupies 64 bytes.
To explain why, assume that the variable starts at address zero (0). The variable member_one takes 4 bytes, so
the next member would normally start at byte 4.
2012-12-13 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.
54
Performance Optimization
Page view 53
1 2 ... 49 50 51 52 53 54 55 56 57 58 59 ... 67 68

Comments to this Manuals

No comments