Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future-proofing for CUnit-derived class sizing #1888

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions rts/Sim/Units/UnitHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ void CUnitHandler::Init() {
GeneralMoveSystem::Init();
UnitTrapCheckSystem::Init();

static_assert(sizeof(CBuilder) >= sizeof(CUnit ), "");
static_assert(sizeof(CBuilder) >= sizeof(CBuilding ), "");
static_assert(sizeof(CBuilder) >= sizeof(CExtractorBuilding), "");
static_assert(sizeof(CBuilder) >= sizeof(CFactory ), "");

{
// set the global (runtime-constant) unit-limit as the sum
// of all team unit-limits, which is *always* <= MAX_UNITS
Expand Down
18 changes: 15 additions & 3 deletions rts/Sim/Units/UnitMemPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@
#define UNIT_MEMPOOL_H

#include "UnitTypes/Builder.h"
#include "UnitTypes/Building.h"
#include "UnitTypes/ExtractorBuilding.h"
#include "UnitTypes/Factory.h"

#include "Sim/Misc/GlobalConstants.h"
#include "System/MemPoolTypes.h"

/* Needs manually listing all derived classes to find the biggest,
* but we probably can't do better, at least without reflection */
union LargestDerivedFromCUnit {
CBuilder builder;
CFactory factory;
CBuilding building;
CExtractorBuilding extractorBuilding;
};

#if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64))
// CBuilder is (currently) the largest derived unit-type
typedef StaticMemPoolT<MAX_UNITS, CBuilder> UnitMemPool;
typedef StaticMemPoolT<MAX_UNITS, LargestDerivedFromCUnit> UnitMemPool;
#else
typedef FixedDynMemPoolT<MAX_UNITS / 1000, MAX_UNITS / 32, CBuilder> UnitMemPool;
typedef FixedDynMemPoolT<MAX_UNITS / 1000, MAX_UNITS / 32, LargestDerivedFromCUnit> UnitMemPool;
#endif

extern UnitMemPool unitMemPool;
Expand Down