buffer_create

This function creates a new buffer and returns it.

The function allocates a portion of memory for the buffer, which can then be used to store different types of data (specified when you write to the buffer using the buffer_writebuffer_poke or buffer_fill function).

The following constants can be used to define the buffer type:

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):

NOTE Byte alignment can be very important as the wrong choice may adversely affect performance.

IMPORTANT You cannot create buffers that are 2 Gibibytes (2,147,483,648 bytes) or larger.

 

Syntax:

buffer_create(size, type, alignment)

Argument Type Description
size Real The size (in bytes) of the buffer.
type Buffer Type Constant The type of buffer to create (see the constants list above).
alignment Real The byte alignment for the buffer

 

Returns:

Buffer

 

Example:

player_buffer = buffer_create(16384, buffer_fixed, 2);

The above code allocates 16384 bytes of memory to a buffer and returns the buffer, storing the reference to it in the variable player_buffer for future use. The buffer is aligned to a two byte boundary.