// // 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. //
// // This header defines the pool_allocator class that allows STL containers // to use the angle::PoolAllocator class by using the pool_allocator // class as the allocator (second) template argument. // // It also defines functions for managing the GlobalPoolAllocator used by the compiler. //
// // There could potentially be many pools with pops happening at // different times. But a simple use is to have a global pop // with everyone using the same global allocator. // extern angle::PoolAllocator *GetGlobalPoolAllocator(); externvoid SetGlobalPoolAllocator(angle::PoolAllocator *poolAllocator);
// // This STL compatible allocator is intended to be used as the allocator // parameter to templatized STL containers, like vector and map. // // It will use the pools for allocation, and not // do any deallocation, but will still do destruction. // template <class T> class pool_allocator
{ public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T *pointer; typedefconst T *const_pointer; typedef T &reference; typedefconst T &const_reference; typedef T value_type;
#ifdefined(__SUNPRO_CC) && !defined(_RWSTD_ALLOCATOR) // libCStd on some platforms have a different allocate/deallocate interface. // Caller pre-bakes sizeof(T) into 'n' which is the number of bytes to be // allocated, not the number of elements. void *allocate(size_type n) { return getAllocator().allocate(n); } void *allocate(size_type n, constvoid *) { return getAllocator().allocate(n); } void deallocate(void *, size_type) {} #else
pointer allocate(size_type n)
{ returnstatic_cast<pointer>(getAllocator().allocate(n * sizeof(T)));
}
pointer allocate(size_type n, constvoid *)
{ returnstatic_cast<pointer>(getAllocator().allocate(n * sizeof(T)));
} void deallocate(pointer, size_type) {} #endif// _RWSTD_ALLOCATOR
void construct(pointer p, const T &val) { new ((void *)p) T(val); } void destroy(pointer p) { p->T::~T(); }
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.