Skip to content

Commit 595984f

Browse files
committed
Clean up allocator TODOs and add max_size
1 parent 1988da0 commit 595984f

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

dart/common/MemoryAllocator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DART_API MemoryAllocator : public Castable<MemoryAllocator>
6969
/// memory.
7070
/// @return On failure, a null pointer
7171
[[nodiscard]] virtual void* allocate(size_t bytes) noexcept = 0;
72-
// TODO(JS): Make this constexpr once migrated to C++20
72+
// Note: Virtual runtime allocation cannot be constexpr by design.
7373

7474
/// Allocates object(s) without calling the constructor.
7575
///
@@ -85,7 +85,7 @@ class DART_API MemoryAllocator : public Castable<MemoryAllocator>
8585
/// @param[in] pointer: Pointer obtained from allocate().
8686
/// @param[in] bytes: The bytes of the allocated memory.
8787
virtual void deallocate(void* pointer, size_t bytes) = 0;
88-
// TODO(JS): Make this constexpr once migrated to C++20
88+
// Note: Virtual runtime deallocation cannot be constexpr by design.
8989

9090
/// Allocates uninitialized storage and constructs an object of type T to the
9191
/// allocated storage.

dart/common/MemoryManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class DART_API MemoryManager final
110110
/// @param[in] pointer: Pointer obtained from allocate().
111111
/// @param[in] bytes: The bytes of the allocated memory.
112112
void deallocate(Type type, void* pointer, size_t bytes);
113-
// TODO(JS): Make this constexpr once migrated to C++20
113+
// Note: Deallocates runtime memory; constexpr is not applicable.
114114

115115
void deallocateUsingFree(void* pointer, size_t bytes);
116116

dart/common/StlAllocator.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ class StlAllocator : public std::allocator<T>
8585
///
8686
/// @param[in] pointer: Pointer obtained from allocate().
8787
/// @param[in] n: Number of objects earlier passed to allocate().
88-
void deallocate(pointer pointer, size_type n);
89-
// TODO(JS): Make this constexpr once migrated to C++20
88+
void deallocate(pointer pointer, size_type n) noexcept;
9089

91-
// TODO(JS): Add size_type max_size() const noexcept;
90+
/// Upper bound on elements that can be allocated.
91+
[[nodiscard]] constexpr size_type max_size() const noexcept
92+
{
93+
return std::allocator_traits<Base>::max_size(*this);
94+
}
9295

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

dart/common/detail/StlAllocator-impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typename StlAllocator<T>::pointer StlAllocator<T>::allocate(
8080

8181
//==============================================================================
8282
template <typename T>
83-
void StlAllocator<T>::deallocate(pointer pointer, size_type n)
83+
void StlAllocator<T>::deallocate(pointer pointer, size_type n) noexcept
8484
{
8585
mBaseAllocator.deallocate(pointer, n * sizeof(T));
8686
}

examples/heightmap/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ dynamics::SimpleFramePtr createHeightmapFrame(
9292

9393
terrainFrame->createVisualAspect();
9494

95-
// TODO(JS): Remove?
9695
auto terrainShape = createHeightmapShape(
9796
xResolution, yResolution, xSize, ySize, zMin, zMax);
9897
terrainFrame->setShape(terrainShape);

0 commit comments

Comments
 (0)