-
-
Notifications
You must be signed in to change notification settings - Fork 305
Message Pools
Directory | Previous | Next |
---|---|---|
Directory | Network Message Interpreters | Serialization Strategy |
It is very likely that you will be creating messages that are not intended to be sent only once, but instead be sent many times over the runtime of your program, for this, message pooling comes in handy.
Forge comes with a generic class built in named MessagePool which will take care of all the backend pooling of messages so that you don't need to. A pool allows you to re-use the memory allocated to a message that you previously used of the same type. Below is an example of how a message pool for the message ChatMessage
is created.
private MessagePool<ChatMessage> _chatMessagePool = new MessagePool<ChatMessage>();
To get a message from the pool you just need to call the Get function _chatMessagePool.Get()
. This will take care of creating a new message if the pool is empty, otherwise it will return the first free message that can be used. Below is an example of how to use the message pool and sending off the message (modified from Network Messages documentation).
ChatMessage m = _chatMessagePool.Get();
m.Name = "Forge";
m.Text = "Hello World!";
IEngineFacade engine = GameObject.FindObjectOfType<ForgeEngineFacade>();
ISocket mySocket = engine.NetworkMediator.SocketFacade.ManagedSocket;
engine.NetworkMediator.SendReliableMessage(m, mySocket.EndPoint);
I would highly recommend using message pools whenever possible to help combat a large amount of GC and have more performant code.
Directory | Previous | Next |
---|---|---|
Directory | Network Message Interpreters | Serialization Strategy |
Getting Started
Network Contract Wizard (NCW)
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
-
Connection Cycle Events
-
Rewinding
-
Network Logging
-
Working with Multiple Sockets
-
Modify Master and Standalone servers
-
NAT Hole Punching
-
UDP LAN Discovery
-
Offline Mode
-
Ping Pong
-
Lobby System
-
Upgrading Forge Remastered to Develop branch or different version
-
Forge Networking Classic to Remastered Migration Guide
-
Script to easily use Forge Networking from sources
-
Run Two Unity Instances with Shared Assets for Easiest Dedicated Client Workflow