- Timestamp:
-
Jun 20, 2007, 10:14:12 PM (15 years ago)
- Author:
-
oetiker
- Comment:
-
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v4
|
v5
|
|
115 | 115 | }}} |
116 | 116 | |
117 | | == Data alignment differences == |
| 117 | == Data Alignment == |
118 | 118 | |
119 | 119 | Most of today's workstations run either 32 or 64 bit. This also has an influence on the data layout. The classic RRDtool data format heavily relies on doubles and longs, bundled into structs. This is a challenging mix for portability: |
… |
… |
|
123 | 123 | * struct members are aligned to either 32 bit or 64 bit boundaries. |
124 | 124 | |
125 | | Below is an example of a the memory layout of several simple structs, made up from integers(32bit) and doubles(64bit). |
| 125 | Below is an example of a the memory layout of several simple structs, made up from integers (32 bit) and doubles (64 bit). |
126 | 126 | |
127 | 127 | {{{ |
128 | | 32 Bit (16 Byte) : IIII.DDDD.DDDD.IIII |
129 | | 64 Bit (24 Byte) : IIII ~~~~.DDDD DDDD.IIII ~~~~ |
| 128 | 32 bit (16 byte) : IIII.DDDD.DDDD.IIII |
| 129 | 64 bit (24 byte) : IIII ~~~~.DDDD DDDD.IIII ~~~~ |
130 | 130 | |
131 | | 32 Bit (12 Byte) : IIII.IIII.IIII |
132 | | 64 Bit (12 Byte) : IIII IIII.IIII |
| 131 | 32 bit (12 byte) : IIII.IIII.IIII |
| 132 | 64 bit (12 byte) : IIII IIII.IIII |
133 | 133 | |
134 | | 32 Bit (16 Byte) : IIII.IIII.DDDD.DDDD.IIII.IIII |
135 | | 64 Bit (24 Byte) : IIII IIII.DDDD DDDD.IIII IIII |
| 134 | 32 bit (16 byte) : IIII.IIII.DDDD.DDDD.IIII.IIII |
| 135 | 64 bit (24 byte) : IIII IIII.DDDD DDDD.IIII IIII |
136 | 136 | }}} |
137 | 137 | |
138 | | This means, that in order to produce a portable data format, structs must be layed out such that they are aligned the same, on 32 and 64 bit systems. |
| 138 | This means, that in order to produce a portable data format, structs must be laid out such that they are aligned the same, on 32 and 64 bit systems. |
| 139 | |
| 140 | == Longs and Integers == |
| 141 | |
| 142 | On 32 bit architectures, integers and longs are 32 bit wide. While longs are normally 64 bit wide on 64 bit architectures. Since the RRDtool data format uses a lot of longs, this also has to be addressed in a portable format. Fortunately, there are datatypes that are less architecture dependent, defined in the inttypes header. |
| 143 | |
| 144 | {{{ |
| 145 | #include <inttypes.h> |
| 146 | uint8_t unsigned_8_bit_integer; |
| 147 | uint32_t unsigned_32_bit_integer; |
| 148 | int64_t signed_64_bit_integer; |
| 149 | /* and so on */ |
| 150 | }}} |
| 151 | |
| 152 | == Conclusion == |
| 153 | |
| 154 | Based on this information a portable RRDtool data format that works at least on |
| 155 | PPC, x86 and SPARC will be not all that difficult to design. |
| 156 | |
| 157 | Information on other architectures is welcome: Alpha, PA-RISC, Itanium, MIPS. |
|