ShareLib: A Shared Memory Infrastructure for Multiplayer Games

Alec Rivers
Masschussets Institute of Technology
Computer Science and Artificial Intelligence Laboratory


ShareLib is a C# library that implements a version of shared memory optimized for multiplayer game communication. It was written as the final project for MIT class 6.824.

Multiplayer games require low latency, and as a result are usually implementing using message passing. However, this is tedious for the programmer. Shared memory is easier for the programmer, but usually focuses on providing strict consistency guarantees, which increase latency. In fact, most variables in multiplayer games typically do not require total ordering or strict consistency. ShareLib is a shared memory library that allows the programmer to specify consistency requirements per variable, allowing the ease of shared memory networking while keeping latency low.

ShareLib is a work in progress and the downloadable library at this point is intended a proof-of-concept.



Example code

With ShareLib, the game world classes can be shared as classes, and will automatically be reflected on all clients. Consider the following example game world class:

public class AttackiosWorld : SharedObject
    public string ServerMessageOfTheDay = "Welcome to Attackios!";

    public ShareList<PlayerInfo> players = new ShareList<PlayerInfo>();
    public ShareList<LaserShot> laserShots = new ShareList<LaserShot>();
    public ShareList<string> chatMessages = new ShareList<string>();
public class PlayerInfo
    public string name = "Unnamed player";

    public Vector2 position = Vector2.ZERO;
    public Angle1 angle = new Angle1(0);
    public double energy = 1.0;
    public double health = 1.0;

To implement chat, a client just has to run the following code to have the chat message reflected on all players' machines. Collisions are handled automatically by the ShareList class.

public void SendChatMessage(string message)


Full size