Original Post
I'm using XNA and c#, and I want to avoid creating any garbage with my message queue. This might turn out to be something of a challenge. It is highly necessary not to allocate too much at runtime on the 360 - the GC is non generational and every 1mb of data you allocate creates a fully recursive mark and sweep which can take several hundred milliseconds.
So far, I've managed to avoid creating a lot of garbage through a combination of object pooling, static buffers, and single object re-use. According to the clr profiler, I have zero allocations. There may be a few allocations when I port to the 360, but right now I'm still detecting runtime allocations using the CLR profiler.
Here is the problem:
I want to do my message handling in two halves. The method call for processing a message queue is as follows:
void handleMessages(MessageQueue input, MessageQueue output)
The idea being that messages in the input are handled and then messages are added to the output. Then, I can tell each of my component lists in turn to handle the messages and produce output. At the end of the frame, the input is cleared, and the two are swapped, so I always have an empty message queue and the queue from the last update.
this odd combination of requirements turns this into something of a challenge - I can't just brute force allocate a huge number of every possible message type. Is there a way to achieve these two goals, or should I abandon one to achieve the other?
So far, I've managed to avoid creating a lot of garbage through a combination of object pooling, static buffers, and single object re-use. According to the clr profiler, I have zero allocations. There may be a few allocations when I port to the 360, but right now I'm still detecting runtime allocations using the CLR profiler.
Here is the problem:
I want to do my message handling in two halves. The method call for processing a message queue is as follows:
void handleMessages(MessageQueue input, MessageQueue output)
The idea being that messages in the input are handled and then messages are added to the output. Then, I can tell each of my component lists in turn to handle the messages and produce output. At the end of the frame, the input is cleared, and the two are swapped, so I always have an empty message queue and the queue from the last update.
this odd combination of requirements turns this into something of a challenge - I can't just brute force allocate a huge number of every possible message type. Is there a way to achieve these two goals, or should I abandon one to achieve the other?