From ecb78919ade4afaac466927ba545975d96b507ab Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 7 Aug 2025 23:55:53 +0200 Subject: Core/PacketIO: Reduce amount of stack space used by a few giant packet classes --- src/server/game/Server/Packets/PacketUtilities.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/server/game/Server/Packets/PacketUtilities.h b/src/server/game/Server/Packets/PacketUtilities.h index f456090c018..3170b11b180 100644 --- a/src/server/game/Server/Packets/PacketUtilities.h +++ b/src/server/game/Server/Packets/PacketUtilities.h @@ -147,6 +147,21 @@ namespace WorldPackets [[noreturn]] void OnInvalidArraySize(std::size_t requestedSize, std::size_t sizeLimit); + template + struct ArrayAllocatorTraits + { + using allocator_type = short_alloc::short_alloc; + using resource_type = typename allocator_type::arena_type; + }; + + // don't store elements inline when size is large + template + struct ArrayAllocatorTraits + { + using allocator_type = std::allocator; + using resource_type = std::allocator; + }; + /** * Utility class for automated prevention of loop counter spoofing in client packets */ @@ -154,8 +169,9 @@ namespace WorldPackets class Array { public: - using allocator_type = short_alloc::short_alloc; - using arena_type = typename allocator_type::arena_type; + using allocator_traits = ArrayAllocatorTraits 0x1000)>; + using allocator_type = typename allocator_traits::allocator_type; + using allocator_resource_type = typename allocator_traits::resource_type; using storage_type = std::vector; @@ -170,7 +186,7 @@ namespace WorldPackets using iterator = typename storage_type::iterator; using const_iterator = typename storage_type::const_iterator; - Array() : _storage(_data) { } + Array() : _storage(_allocatorResource) { } Array(Array const& other) : Array() { @@ -253,7 +269,7 @@ namespace WorldPackets } private: - arena_type _data; + allocator_resource_type _allocatorResource; storage_type _storage; }; -- cgit v1.2.3