From 7f97e6793114518010647f470b6cb0e219258fa5 Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Wed, 13 May 2015 19:43:35 +0100 Subject: [PATCH 1/2] Saner allocation policy for DataPacks. --- core/CDataPack.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/CDataPack.cpp b/core/CDataPack.cpp index 59b0bbc0..268d619d 100644 --- a/core/CDataPack.cpp +++ b/core/CDataPack.cpp @@ -33,7 +33,7 @@ #include #include "CDataPack.h" -#define DATAPACK_INITIAL_SIZE 512 +#define DATAPACK_INITIAL_SIZE 64 CDataPack::CDataPack() { @@ -64,9 +64,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() From fd48f4adfdf269fe7a2acd954299de9a0d73f41c Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Wed, 13 May 2015 19:43:53 +0100 Subject: [PATCH 2/2] Report size for DataPack Handles. --- core/CDataPack.h | 1 + core/logic/smn_datapacks.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/CDataPack.h b/core/CDataPack.h index 48883f0d..ec1195d2 100644 --- a/core/CDataPack.h +++ b/core/CDataPack.h @@ -61,6 +61,7 @@ public: //IDataPack void PackFunction(cell_t function); public: void Initialize(); + inline size_t GetCapacity() const { return m_capacity; } private: void CheckSize(size_t sizetype); private: diff --git a/core/logic/smn_datapacks.cpp b/core/logic/smn_datapacks.cpp index 9a369dbe..9d39c052 100644 --- a/core/logic/smn_datapacks.cpp +++ b/core/logic/smn_datapacks.cpp @@ -31,9 +31,14 @@ #include "common_logic.h" #include -#include #include +// This just in from the bucket o' hacks department. +// One day, IDataPack will go away and CDataPack will be merged into this file. +// This internal header is included directly to access GetCapacity, +// which can not be added to the public interface due to ABI issues. +#include "../CDataPack.h" + HandleType_t g_DataPackType; class DataPackNatives : @@ -63,6 +68,12 @@ public: { g_pSM->FreeDataPack(reinterpret_cast(object)); } + bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize) + { + CDataPack *pack = reinterpret_cast(object); + *pSize = sizeof(CDataPack) + pack->GetCapacity(); + return true; + } }; static cell_t smn_CreateDataPack(IPluginContext *pContext, const cell_t *params)