Legacy GM buffer alignment - deciding the size of buffer alignment

B

Barack Pálinka

Guest
Hi,i'm wondering how do you decide the size of the buffer alignment?
because here it's 2: player_buffer = buffer_create(16384, buffer_fixed, 2);
but what will happen if i set it to 1 or 3?
Thanks in advance!
 

Bingdom

Googledom
Hi,i'm wondering how do you decide the size of the buffer alignment?
It tells you in the manual, from the function buffer_create
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.
 
Top