Skip to content

Commit

Permalink
Allocate data seperately from MapBlock class again
Browse files Browse the repository at this point in the history
This effectively reverts commit b3503e7.
  • Loading branch information
sfan5 committed Dec 16, 2023
1 parent 2c2bc4a commit cb6e3ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/mapblock.cpp
Expand Up @@ -70,6 +70,7 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef):
m_parent(parent),
m_pos(pos),
m_pos_relative(pos * MAP_BLOCKSIZE),
data(new MapNode[nodecount]),
m_gamedef(gamedef)
{
reallocate();
Expand All @@ -83,6 +84,8 @@ MapBlock::~MapBlock()
mesh = nullptr;
}
#endif

delete[] data;
}

bool MapBlock::onObjectsActivation()
Expand Down
8 changes: 7 additions & 1 deletion src/mapblock.h
Expand Up @@ -502,6 +502,13 @@ class MapBlock
*/
v3s16 m_pos_relative;

/*
* Note that this is not an inline array because that has implications on
* heap fragmentation (the array is exactly 16K), CPU caches and/or
* optimizability of algorithms working on this array.
*/
MapNode *const data; // of `nodecount` elements

IGameDef *m_gamedef;

/*
Expand Down Expand Up @@ -558,7 +565,6 @@ class MapBlock
*/
int m_refcount = 0;

MapNode data[nodecount];
NodeTimerList m_node_timers;
};

Expand Down

0 comments on commit cb6e3ac

Please sign in to comment.