Tweak EventHook data allocation based on testing.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-04 13:43:51 +02:00
parent 5cd5a634e2
commit 9b9b644143
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 4 additions and 4 deletions

View File

@ -19,11 +19,11 @@ namespace CreatureLib::Battling {
size_t _capacity;
uint8_t* _memory = nullptr;
// Consider tweaking this size to be in line with the normal amount of events we use.
static const size_t defaultSize = 1024;
static constexpr size_t initialSize = 2048;
static constexpr size_t stepSize = 1024;
public:
EventHook() : _offset(0), _capacity(defaultSize) {
EventHook() : _offset(0), _capacity(2048) {
auto ptr = malloc(_capacity);
if (ptr == nullptr) {
THROW_CREATURE("Out of memory.");
@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
if (_listeners.size() == 0)
return;
if (_offset + sizeof(T) >= _capacity) {
_capacity += defaultSize;
_capacity += stepSize;
auto newPtr = realloc(_memory, _capacity);
if (newPtr == nullptr) {
THROW_CREATURE("Out of memory.");