// Adapter for use of ArenaAllocator in STL containers. // Use ArenaAllocator::Adapter() to create an adapter to pass to container constructors. // For example, // struct Foo { // explicit Foo(ArenaAllocator* allocator) // : foo_vector(allocator->Adapter(kArenaAllocMisc)), // foo_map(std::less<int>(), allocator->Adapter()) { // } // ArenaVector<int> foo_vector; // ArenaSafeMap<int, int> foo_map; // }; template <typename T> class ArenaAllocatorAdapter;
template <typename T> using ArenaDeque = std::deque<T, ArenaAllocatorAdapter<T>>;
template <typename T> using ArenaForwardList = std::forward_list<T, ArenaAllocatorAdapter<T>>;
template <typename T> using ArenaList = std::list<T, ArenaAllocatorAdapter<T>>;
template <typename T> using ArenaQueue = std::queue<T, ArenaDeque<T>>;
template <typename T> using ArenaVector = dchecked_vector<T, ArenaAllocatorAdapter<T>>;
template <typename T> class ArenaAllocatorAdapter : private ArenaAllocatorAdapterKind { public: using value_type = T; using pointer = T*; using reference = T&; using const_pointer = const T*; using const_reference = const T&; using size_type = size_t; using difference_type = ptrdiff_t;
template <typename U> struct rebind { using other = ArenaAllocatorAdapter<U>;
};
// Special deleter that only calls the destructor. Also checks for double free errors. template <typename T> class ArenaDelete { static constexpr uint8_t kMagicFill = 0xCE;
protected: // Used for variable sized objects such as RegisterLine.
ALWAYS_INLINE void ProtectMemory(T* ptr, size_t size) const { if (kRunningOnMemoryTool) {
memset(static_cast<void*>(ptr), kMagicFill, size);
MEMORY_TOOL_MAKE_NOACCESS(ptr, size);
} elseif (kIsDebugBuild) { // Write a magic value to try and catch use after free errors.
memset(static_cast<void*>(ptr), kMagicFill, size);
}
}
// In general we lack support for arrays. We would need to call the destructor on each element, // which requires access to the array size. Support for that is future work. // // However, we can support trivially destructible component types, as then a destructor doesn't // need to be called. template <typename T> class ArenaDelete<T[]> { public: voidoperator()([[maybe_unused]] T* ptr) const {
static_assert(std::is_trivially_destructible_v<T>, "ArenaUniquePtr does not support non-trivially-destructible arrays."); // TODO: Implement debug checks, and MEMORY_TOOL support.
}
};
// Arena unique ptr that only calls the destructor of the element. template <typename T> using ArenaUniquePtr = std::unique_ptr<T, ArenaDelete<T>>;
} // namespace art
#endif// ART_LIBARTBASE_BASE_ARENA_CONTAINERS_H_
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.