Apart from the buffer type, you will also have to set the
byte alignment for the buffer. This value will vary depending on the data that you wish to store in the buffer, and in most cases a value of 1 is perfectly fine. However, be aware that for some operations a specific alignment is
essential, and an incorrect alignment may cause errors (for further details on alignment see
Buffers). The following is a general guide to show which values are most appropriate for each data type (when in doubt, use an alignment of 1):
- Strings should be aligned to 1 byte.
- Signed or unsigned 8bit integers can be aligned to any value, but note that for a fast buffer (see buffer_write) it must be aligned to 1.
- Signed or unsigned 16bit integers should be aligned to 2 bytes.
- Signed or unsigned 32bit integers should be aligned to 4 bytes
- Floats of up to 16bits should be aligned to 2 bytes. (Not currently supported!)
- Floats of up to 32bits should be aligned to 4 bytes.
- Floats of up to 64bits should be aligned to 8 bytes.
NOTE: Byte alignment can be very important as the wrong choice may adversely affect performance.