Ducktards
  • Home
  • Behind the Scenes
  • Daily Dev
  • Server stuff

Buffers

15/6/2016

 

Buffers are incredibly useful! They can be used to send data over the internet, to save and load from disk, or simply for general storage! Hopefully this article will help you understand how they work! Hit read more to expand!
Picture

        Buffers are really simple!
Picture








​
​

Create one any size
Picture
   







​

​

   or change the size later
Picture

​

​





​


       You write data to it
Picture

​



​

​

​


         which pushes the seek along
Picture
     







​
​

        until the buffer is full.
Picture

​





​



​

       You can also move the seek manually.
Picture

​






​


​
      You'll need to, if you want to read the data again.
Picture

​



​




​


          as reading & writing both push the seek.
Picture













​Unless
 you use the special  functions!
Picture





​

​
​


​


     You can 'peek' at data in the buffer
Picture

​




​





      ​and you can 'poke' new data in too
Picture


​

​







​neither of which move the seek.
Picture



​



​



You probably won't use those much though!
Picture

A great way to visualise a buffer, is to think of the youtube playback bar. It can be any size you want, but every position on it contains data.

The seek starts at the beginning, and goes through every frame until it reaches the end. However, if you try and move the header, it might lag a bit.



​



​

​
​
Terminology
Really easy stuff! Exactly what you'd expect.
Picture

​
​





​
​




​
​


​Types of buffer

​Essentially, there are two. And they're pretty self explanatory!
Picture


​Fixed buffers

The only way they'll change size, is if you resize them manually. 
​Growing buffers
When you write to them, they get larger as necessary.​​​










​
Creating a buffer
Picture
Picture
 








​






​
Writing to a buffer
Picture
Picture
​Every time you write something, the seek position will be moved along accordingly.








​
Picture
Picture
It works exactly as you'd expect it to!

















​
Moving the seek position
Picture
Picture
Move the seek to the beginning, no offset.









​
Picture
Picture
Move the seek to the beginning, with an offset of 1.









​
Picture
Picture
This one is slightly confusing!

When you use buffer_seek_end, the offset will be flipped. An offset of 1 will move the seek backwards  1 not forwards.










​
Picture
Picture
Move the seek 2 bytes backwards, from where it was.










​




​
Reading from a buffer
coming soon! Click that approve button if you liked it so far!

    Only show:

    All
    Dev
    Documentation
    Networking
    Tutorial

  • Home
  • Behind the Scenes
  • Daily Dev
  • Server stuff