Data Structures!

Lets talk briefly about data structures.

When programming games you often need to store information. Such as storing lists of items that your character has, or certain achievements that your players have achieved whilst playing your game. Most commonly array would be used for this situations by programmers. However sometimes you want to do more complicating operations for better performances. I don’t hate Arrays or anything, Arrays are great we all love it, as its in most languages, and easy to declare as they provide handy [] syntax and what not. But the point of this post is to acknowledge that there are other data structures to aid game programmers : ). As a good programmer you should know various types of data structures that can be used to keep your code optimized.

Some of the three common data structures used for games, the Linked List, Tree, and Hash Table, all used for various situations.

The Linked List Data Structure

Similar to arrays as they both store a collection of data, although linked list are not ordered by their physical placement in memory but rather by  logical links (such as pointers in c++ or any reference ).

Each objects or otherwise known as nodes are linked in a linear sequence to other same kind of objects. These nodes contains two fields a “data” field to store whatever element type the list holds for the program and a “next” field which points to the next node. Each nodes are allocated in the heap with a call to malloc(), so the node memory continues to exit until it explicitly deallocates with a free().

The advantages of this linked list allows more flexibility in organizing the data, also provides  a fast method to allocate and deallocate objects from the list.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s