added cmake option for disable allocator
This commit is contained in:
parent
62f81be11a
commit
8db6b96e10
6 changed files with 31 additions and 12 deletions
|
@ -93,10 +93,15 @@ option(TRY_USE_CCACHE "Try use ccache" ON)
|
|||
option(BUILD_PCH "Build using precompiled headers." ON)
|
||||
option(BUILD_UNITY "Build using unity build." ON)
|
||||
option(TRY_BUILD_SHARED_LIBS_IN_DEBUG "Build shared libs if possible in debug" OFF)
|
||||
option(BUILD_ASAN "Enable Address Sanitizer" OFF)
|
||||
option(BUILD_ASAN "Enable Address Sanitizer" OFF) # if ON, then disabled custom allocator
|
||||
option(BUILD_ALLOCATOR "Enable Custom allocator (used for engraving)" ON)
|
||||
option(QML_LOAD_FROM_SOURCE "Load qml files from source (not resource)" OFF)
|
||||
option(TRACE_DRAW_OBJ_ENABLED "Trace draw objects" OFF)
|
||||
|
||||
if (BUILD_ASAN)
|
||||
set(BUILD_ALLOCATOR OFF)
|
||||
endif()
|
||||
|
||||
set(QT_SUPPORT ON)
|
||||
|
||||
option(USE_SYSTEM_FREETYPE "Use system FreeType" OFF) # requires freetype >= 2.5.2, does not work on win
|
||||
|
|
|
@ -14,7 +14,11 @@ else()
|
|||
add_definitions(-DNO_QT_SUPPORT)
|
||||
endif()
|
||||
|
||||
add_definitions(-DHAW_PROFILER_ENABLED)
|
||||
add_definitions(-DHAW_PROFILER_ENABLED)
|
||||
|
||||
if (NOT BUILD_ALLOCATOR)
|
||||
add_definitions(-DCUSTOM_ALLOCATOR_DISABLED)
|
||||
endif()
|
||||
|
||||
if (CC_IS_GCC)
|
||||
message(STATUS "Using Compiler GCC ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
|
|
|
@ -59,14 +59,14 @@ std::shared_ptr<EngravingProject> EngravingProject::create(const MStyle& style)
|
|||
|
||||
EngravingProject::EngravingProject()
|
||||
{
|
||||
ObjectAllocator::enabled++;
|
||||
ObjectAllocator::used++;
|
||||
}
|
||||
|
||||
EngravingProject::~EngravingProject()
|
||||
{
|
||||
delete m_masterScore;
|
||||
|
||||
ObjectAllocator::enabled--;
|
||||
ObjectAllocator::used--;
|
||||
|
||||
AllocatorsRegister::instance()->printStatistic("=== Destroy engraving project ===");
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
using namespace mu;
|
||||
|
||||
int ObjectAllocator::enabled = 0;
|
||||
int ObjectAllocator::used = 0;
|
||||
size_t ObjectAllocator::DEFAULT_BLOCK_SIZE(1024 * 256); // 256 kB
|
||||
|
||||
static inline size_t align(size_t n)
|
||||
|
@ -205,6 +205,15 @@ ObjectAllocator::Info ObjectAllocator::stateInfo() const
|
|||
return info;
|
||||
}
|
||||
|
||||
bool ObjectAllocator::enabled()
|
||||
{
|
||||
#ifdef CUSTOM_ALLOCATOR_DISABLED
|
||||
return false;
|
||||
#else
|
||||
return used;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// AllocatorsRegister
|
||||
// ============================================
|
||||
|
|
|
@ -35,23 +35,23 @@ public: \
|
|||
return a; \
|
||||
} \
|
||||
static void* operator new(size_t sz) { \
|
||||
return ObjectAllocator::enabled ? allocator().alloc(sz) : ::operator new(sz); \
|
||||
return ObjectAllocator::enabled() ? allocator().alloc(sz) : ::operator new(sz); \
|
||||
} \
|
||||
static void operator delete(void* ptr, size_t sz) { \
|
||||
if (ObjectAllocator::enabled) { \
|
||||
if (ObjectAllocator::enabled()) { \
|
||||
allocator().free(ptr, sz); \
|
||||
} else { \
|
||||
::operator delete(ptr, sz); \
|
||||
} \
|
||||
} \
|
||||
static void* operator new[](size_t sz) { \
|
||||
return ObjectAllocator::enabled ? allocator().not_supported("new[]") : ::operator new[](sz); \
|
||||
return ObjectAllocator::enabled() ? allocator().not_supported("new[]") : ::operator new[](sz); \
|
||||
} \
|
||||
static void* operator new(size_t sz, void* ptr) { \
|
||||
return ObjectAllocator::enabled ? allocator().not_supported("new(size_t, void*)") : ::operator new(sz, ptr); \
|
||||
return ObjectAllocator::enabled() ? allocator().not_supported("new(size_t, void*)") : ::operator new(sz, ptr); \
|
||||
} \
|
||||
static void operator delete[](void* ptr, size_t sz) { \
|
||||
if (ObjectAllocator::enabled) { \
|
||||
if (ObjectAllocator::enabled()) { \
|
||||
allocator().not_supported("delete[]"); \
|
||||
} else { \
|
||||
::operator delete[](ptr, sz); \
|
||||
|
@ -104,7 +104,8 @@ public:
|
|||
|
||||
Info stateInfo() const;
|
||||
|
||||
static int enabled;
|
||||
static bool enabled();
|
||||
static int used;
|
||||
|
||||
private:
|
||||
struct Chunk {
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
|
||||
void SetUp() override
|
||||
{
|
||||
ObjectAllocator::enabled++;
|
||||
ObjectAllocator::used++;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue