Tweak EventHook data allocation based on testing.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
5cd5a634e2
commit
9b9b644143
|
@ -19,11 +19,11 @@ namespace CreatureLib::Battling {
|
||||||
size_t _capacity;
|
size_t _capacity;
|
||||||
uint8_t* _memory = nullptr;
|
uint8_t* _memory = nullptr;
|
||||||
|
|
||||||
// Consider tweaking this size to be in line with the normal amount of events we use.
|
static constexpr size_t initialSize = 2048;
|
||||||
static const size_t defaultSize = 1024;
|
static constexpr size_t stepSize = 1024;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventHook() : _offset(0), _capacity(defaultSize) {
|
EventHook() : _offset(0), _capacity(2048) {
|
||||||
auto ptr = malloc(_capacity);
|
auto ptr = malloc(_capacity);
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
THROW_CREATURE("Out of memory.");
|
THROW_CREATURE("Out of memory.");
|
||||||
|
@ -42,7 +42,7 @@ namespace CreatureLib::Battling {
|
||||||
if (_listeners.size() == 0)
|
if (_listeners.size() == 0)
|
||||||
return;
|
return;
|
||||||
if (_offset + sizeof(T) >= _capacity) {
|
if (_offset + sizeof(T) >= _capacity) {
|
||||||
_capacity += defaultSize;
|
_capacity += stepSize;
|
||||||
auto newPtr = realloc(_memory, _capacity);
|
auto newPtr = realloc(_memory, _capacity);
|
||||||
if (newPtr == nullptr) {
|
if (newPtr == nullptr) {
|
||||||
THROW_CREATURE("Out of memory.");
|
THROW_CREATURE("Out of memory.");
|
||||||
|
|
Loading…
Reference in New Issue