// // Copyright 2002 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. //
// // Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme. // #define POOL_ALLOCATOR_NEW_DELETE \ void *operatornew(size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ void *operatornew(size_t, void *_Where) { return (_Where); } \ voidoperatordelete(void *) {} \ voidoperatordelete(void *, void *) {} \ void *operatornew[](size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \ void *operatornew[](size_t, void *_Where) { return (_Where); } \ voidoperatordelete[](void *) {} \ voidoperatordelete[](void *, void *) {}
// // Pool version of string. // typedef pool_allocator<char> TStringAllocator; typedef std::basic_string<char, std::char_traits<char>, TStringAllocator> TString; typedef std::basic_ostringstream<char, std::char_traits<char>, TStringAllocator> TStringStream;
// // Persistent memory. Should only be used for strings that survive across compiles. // using TPersistString = std::string; using TPersistStringStream = std::ostringstream;
// // Pool allocator versions of vectors, lists, and maps // template <class T> class TVector : public std::vector<T, pool_allocator<T>>
{ public:
POOL_ALLOCATOR_NEW_DELETE
template <class K, class D, class H = std::hash<K>, class CMP = std::equal_to<K>> class TUnorderedMap : public std::unordered_map<K, D, H, CMP, pool_allocator<std::pair<const K, D>>>
{ public:
POOL_ALLOCATOR_NEW_DELETE typedef pool_allocator<std::pair<const K, D>> tAllocator;
TUnorderedMap() : std::unordered_map<K, D, H, CMP, tAllocator>() {} // use correct two-stage name lookup supported in gcc 3.4 and above
TUnorderedMap(const tAllocator &a)
: std::unordered_map<K, D, H, CMP, tAllocator>(
std::unordered_map<K, D, H, CMP, tAllocator>::key_compare(),
a)
{}
};
template <class K, class D, class CMP = std::less<K>> class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<const K, D>>>
{ public:
POOL_ALLOCATOR_NEW_DELETE typedef pool_allocator<std::pair<const K, D>> tAllocator;
TMap() : std::map<K, D, CMP, tAllocator>() {} // use correct two-stage name lookup supported in gcc 3.4 and above
TMap(const tAllocator &a)
: std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a)
{}
};
// Basic implementation of C++20's span for use with pool-allocated containers (TVector) or static // arrays. This is used by the array sizes member of TType to allow arrayed types to be // constexpr-constructed. // See the reference for std::span here: https://en.cppreference.com/w/cpp/container/span template <typename T> class TSpan
{ public: typedef size_t size_type;
// Note: the pointer is taken out of the TVector because TVector's memory is pool allocated, // so the memory will live on even if the TVector is destroyed. template <typename S>
TSpan(const TVector<S> &vec) : mData(vec.data()), mSize(vec.size())
{} template <typename S>
TSpan &operator=(const TVector<S> &vec)
{
mData = vec.data();
mSize = vec.size(); return *this;
}
// Allocate a char array in the global memory pool. str must be a null terminated string. strLength // is the length without the null terminator. inlineconstchar *AllocatePoolCharArray(constchar *str, size_t strLength)
{
size_t requiredSize = strLength + 1; char *buffer = static_cast<char *>(GetGlobalPoolAllocator()->allocate(requiredSize));
memcpy(buffer, str, requiredSize);
ASSERT(buffer[strLength] == '\0'); return buffer;
}
// Initialize a new stream which must be imbued with the classic locale template <typename T>
T InitializeStream()
{
T stream;
stream.imbue(std::locale::classic()); return stream;
}
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.