Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Apr 5, 2024
1 parent c28350e commit df64a25
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 223 deletions.
2 changes: 0 additions & 2 deletions dart/common/FreeListAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ void FreeListAllocator::MemoryBlockHeader::merge(MemoryBlockHeader* other)
}

//==============================================================================
#if DART_BUILD_MODE_DEBUG
bool FreeListAllocator::MemoryBlockHeader::isValid() const
{
if (mPrev != nullptr && mPrev->mNext != this) {
Expand All @@ -385,6 +384,5 @@ bool FreeListAllocator::MemoryBlockHeader::isValid() const

return true;
}
#endif

} // namespace dart::common
2 changes: 0 additions & 2 deletions dart/common/FreeListAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ class FreeListAllocator : public MemoryAllocator
/// Merges this memory block with the given memory block
void merge(MemoryBlockHeader* other);

#if DART_BUILD_MODE_DEBUG
/// [Debug only] Returns whether this memory block is valid
bool isValid() const;
#endif
};

/// Allocates a new memory block for \c sizeToAllocate bytes
Expand Down
28 changes: 1 addition & 27 deletions dart/common/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "dart/common/MemoryManager.hpp"

#if DART_BUILD_MODE_DEBUG
#ifndef NDEBUG
#include "dart/common/Logging.hpp"
#endif

Expand All @@ -49,11 +49,7 @@ MemoryManager& MemoryManager::GetDefault()
MemoryManager::MemoryManager(MemoryAllocator& baseAllocator)
: mBaseAllocator(baseAllocator),
mFreeListAllocator(mBaseAllocator),
#if DART_BUILD_MODE_RELEASE
mPoolAllocator(mFreeListAllocator)
#else
mPoolAllocator(mFreeListAllocator.getInternalAllocator())
#endif
{
// Do nothing
}
Expand All @@ -73,21 +69,13 @@ MemoryAllocator& MemoryManager::getBaseAllocator()
//==============================================================================
FreeListAllocator& MemoryManager::getFreeListAllocator()
{
#if DART_BUILD_MODE_RELEASE
return mFreeListAllocator;
#else
return mFreeListAllocator.getInternalAllocator();
#endif
}

//==============================================================================
PoolAllocator& MemoryManager::getPoolAllocator()
{
#if DART_BUILD_MODE_RELEASE
return mPoolAllocator;
#else
return mPoolAllocator.getInternalAllocator();
#endif
}

//==============================================================================
Expand Down Expand Up @@ -144,20 +132,6 @@ void MemoryManager::deallocateUsingPool(void* pointer, size_t bytes)
deallocate(Type::Pool, pointer, bytes);
}

#if DART_BUILD_MODE_DEBUG
//==============================================================================
bool MemoryManager::hasAllocated(void* pointer, size_t size) const noexcept
{
if (mFreeListAllocator.hasAllocated(pointer, size))
return true;

if (mPoolAllocator.hasAllocated(pointer, size))
return true;

return false;
}
#endif

//==============================================================================
void MemoryManager::print(std::ostream& os, int indent) const
{
Expand Down
16 changes: 0 additions & 16 deletions dart/common/MemoryManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
#ifndef DART_COMMON_MEMORYMANAGER_HPP_
#define DART_COMMON_MEMORYMANAGER_HPP_

#if DART_BUILD_MODE_DEBUG
#include <mutex>
#endif
#include <dart/common/FreeListAllocator.hpp>
#include <dart/common/PoolAllocator.hpp>

Expand Down Expand Up @@ -151,11 +148,6 @@ class MemoryManager final
template <typename T>
void destroyUsingPool(T* pointer) noexcept;

#if DART_BUILD_MODE_DEBUG
/// Returns true if a pointer is allocated by the internal allocator.
[[nodiscard]] bool hasAllocated(void* pointer, size_t size) const noexcept;
#endif

/// Prints state of the memory manager.
void print(std::ostream& os = std::cout, int indent = 0) const;

Expand All @@ -167,19 +159,11 @@ class MemoryManager final
/// The base allocator to allocate memory chunk.
MemoryAllocator& mBaseAllocator;

#if DART_BUILD_MODE_RELEASE
/// The free list allocator.
FreeListAllocator mFreeListAllocator;

/// The pool allocator.
PoolAllocator mPoolAllocator;
#else
/// The free list allocator.
FreeListAllocator::Debug mFreeListAllocator;

/// The pool allocator.
PoolAllocator::Debug mPoolAllocator;
#endif
};

} // namespace dart::common
Expand Down
10 changes: 2 additions & 8 deletions dart/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
|| (DART_MINOR_VERSION <= y && DART_PATCH_VERSION <= z)))

// Deprecated in 6.14
#define DART_VERSION_AT_LEAST(x, y, z) \
DART_VERSION_GE(x, y, z)
#define DART_VERSION_AT_LEAST(x, y, z) DART_VERSION_GE(x, y, z)

// Deprecated in 6.14
#define DART_MAJOR_MINOR_VERSION_AT_LEAST(x, y) \
Expand All @@ -44,8 +43,7 @@
&& (DART_MINOR_VERSION > y || (DART_MINOR_VERSION >= y))))

// Deprecated in 6.14
#define DART_VERSION_AT_MOST(x, y, z) \
DART_VERSION_LE(x, y, z)
#define DART_VERSION_AT_MOST(x, y, z) DART_VERSION_LE(x, y, z)

// Deprecated in 6.14
#define DART_MAJOR_MINOR_VERSION_AT_MOST(x, y) \
Expand All @@ -62,10 +60,6 @@
#define DART_COMPILER_MSVC
#endif

// Indicates the build mode used for compiling
#cmakedefine01 DART_BUILD_MODE_DEBUG
#cmakedefine01 DART_BUILD_MODE_RELEASE

#cmakedefine01 HAVE_NLOPT
#cmakedefine01 HAVE_IPOPT
#cmakedefine01 HAVE_PAGMO
Expand Down
Loading

0 comments on commit df64a25

Please sign in to comment.