From f7c4ed050fe20b0a978fcd1f13b642790783a023 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 13 Jul 2015 23:49:51 +0200 Subject: [PATCH] Improve DataPack memory allocation --- amxmodx/CDataPack.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/amxmodx/CDataPack.cpp b/amxmodx/CDataPack.cpp index a7cf05fa..e721d59c 100644 --- a/amxmodx/CDataPack.cpp +++ b/amxmodx/CDataPack.cpp @@ -29,7 +29,7 @@ #include "CDataPack.h" -#define DATAPACK_INITIAL_SIZE 512 +#define DATAPACK_INITIAL_SIZE 64 CDataPack::CDataPack() { @@ -60,9 +60,10 @@ void CDataPack::CheckSize(size_t typesize) do { m_capacity *= 2; - m_pBase = (char *)realloc(m_pBase, m_capacity); - m_curptr = m_pBase + pos; - } while (m_curptr - m_pBase + typesize > m_capacity); + } while (pos + typesize > m_capacity); + + m_pBase = (char *)realloc(m_pBase, m_capacity); + m_curptr = m_pBase + pos; } void CDataPack::ResetSize()