You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR makes two changes to remove all dynamic allocations for NetPacket:
Refactors NetPacket::ConstructBigCommandList so that NetPacket doesn't have to be memory pooled.
Removes memory pool for NetPacket, so that it can be stack allocated.
TODO:
Verify everything works ok.
Caball009
added
Minor
Severity: Minor < Major < Critical < Blocker
Refactor
Edits the code with insignificant behavior changes, is never user facing
labels
Jul 9, 2026
This PR removes all dynamic (pool/heap) allocations for NetPacket by eliminating its MemoryPoolObject base class and replacing ConstructBigCommandPacketList (which returned a list of heap-allocated packets) with ConstructBigCommandList (which returns a single NetCommandList*). Call sites in Connection.cpp and ConnectionManager.cpp now use stack-allocated NetPacket instances.
ConstructBigCommandList: The new implementation builds chunk refs and adds them directly to a NetCommandList via the addMessage(NetCommandRef*&) overload, which takes ownership — no leak. As a side effect it fixes a relay self-assignment bug in the old code where the inner ref variable shadowed the function parameter, leaving every chunk's relay at its default value of 0.
sendNetCommandMsg / doSend / doRelay: Stack-allocated NetPacket replaces the static singleton (in sendNetCommandMsg) and per-iteration heap allocations (in doSend and doRelay). MAX_PACKET_SIZE tops out at 1100 bytes so stack usage is well within safe limits.
Pool entries: Both GameMemoryInitPools_Generals.inl and GameMemoryInitPools_GeneralsMD.inl remove the NetPacket pool row, consistent with the class no longer being pool-managed.
Confidence Score: 5/5
Safe to merge once the author completes their own functional verification (noted in the PR TODO).
The refactoring is mechanically sound. Ownership is correctly transferred to NetCommandList via the addMessage(NetCommandRef*&) overload, ref-counting through wrapperMsg is preserved, and MAX_PACKET_SIZE (≤1100 bytes) keeps stack usage well within normal limits. The change also incidentally fixes the old relay self-assignment bug. No regressions were found in the changed paths.
No files require special attention beyond the author completing their functional test pass.
Important Files Changed
Filename
Overview
Core/GameEngine/Include/GameNetwork/NetPacket.h
Removes MemoryPoolObject base class and pool glue macros; changes constructor to take TransportMessage by const-ref; replaces NetPacketList/ConstructBigCommandPacketList with new ConstructBigCommandList returning NetCommandList*.
Core/GameEngine/Source/GameNetwork/NetPacket.cpp
Rewrites ConstructBigCommandPacketList as ConstructBigCommandList, allocating chunks directly into a NetCommandList. Also fixes a relay self-assignment bug from the old code. Ownership model is correct: addMessage(NetCommandRef*&) takes ownership of each chunkRef.
Core/GameEngine/Source/GameNetwork/Connection.cpp
Replaces heap-allocated NetPacket (static singleton in sendNetCommandMsg and per-iteration allocation in doSend) with stack-allocated instances. Simplifies the big-command path to iterate directly over NetCommandList instead of NetPacketList.
Switches doRelay to use stack-allocated NetPacket per loop iteration; correctly removes the outer-loop deleteInstance(packet) which was a nullptr no-op in the original.
Caball009
changed the title
refactor(network): Remove memory pool for NetPacket
refactor(network): Remove dynamic allocations for NetPacket
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MinorSeverity: Minor < Major < Critical < BlockerRefactorEdits the code with insignificant behavior changes, is never user facing
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes two changes to remove all dynamic allocations for
NetPacket:NetPacket::ConstructBigCommandListso thatNetPacketdoesn't have to be memory pooled.NetPacket, so that it can be stack allocated.TODO: