Buffers
GameMaker has a number of specific functions related to creating, modifying and loading/saving buffers. A buffer is a region of physical memory used to temporarily hold data while it's being moved from one place to another or manipulated in some way. For example, you can use a buffer to hold packet data awaiting transmission over a network or for storing a packet that has been received over a network.
Usage Notes
Before using buffers please note the following points:
- When a buffer is created, it is automatically cleared and filled to 0.
- The "size" argument of the buffer functions always refers to the size in bytes of the buffer.
- The "alignment" argument refers to how data is stored within a buffer. If your alignment is set to say, 4, and you write a single piece of data which is 1 byte in size then do a buffer_tell, you'll get an offset of 1. However, if you write another piece of data, also 1 byte in size, then do a buffer_tell, you'll get an offset of 5 as the alignment has "padded" the data to that size. Alignment only affects where things are written to, so if you do a buffer_tell after you write something, it'll return the current write position which immediately follows the data you've written. Note, however, that if you then write another piece of data, internally the buffer will move the write position along to the next multiple of the alignment size before actually writing the piece of data.
- When dealing with "offset", this is the value in bytes to offset the data by within the given buffer. So if your buffer is 2 byte aligned and you want to skip the first 4 aligned places, you would have an offset of 2 * 4 bytes.
- Some of the buffer functions also create a new buffer (like buffer_load for example). Remember that these buffers will also need to be removed from memory when not in use using the buffer_delete function.
- The memory used for creating buffers is system memory so even when the game doesn't have focus, any data stored in a buffer should be safe, however if the app is closed or restarted then it will be lost.
The following pages explain how buffers work within the context of GameMaker and contain a couple of code examples for those users that are unsure of how to use them:
IMPORTANT When you create a buffer, a reference to the new buffer is returned. After the buffer is destroyed, we recommend that you set the variable that holds a buffer reference to -1.
Function Reference
General
Loading & Saving
Compression
Async Groups
Surfaces
Hashes & Checksums
Encoding
Loading & Saving Game States
NOTE These functions require a buffer to have been created previously.
Vertex Buffers