#pragma once #include "PoolAllocator.hpp" #include <memory> #ifdef _WIN32 # include <xstddef> #endif namespace sprawl { namespace memory { template<typename T, typename allocator=PoolAllocator<sizeof(T)> > class StlWrapper { public: typedef StlWrapper<T, allocator> other; typedef T value_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef T const& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; #ifdef _WIN32 # if _HAS_CPP0X typedef std::false_type propagate_on_container_copy_assignment; typedef std::false_type propagate_on_container_move_assignment; typedef std::false_type propagate_on_container_swap; StlWrapper<T, allocator> select_on_container_copy_construction() const { // return this allocator return (*this); } # endif #endif template<class T2> struct rebind { typedef StlWrapper<T2, typename allocator::template rebind<T2>::otherAllocator> other; }; value_type* address(value_type& val) const { return reinterpret_cast<value_type*>(&reinterpret_cast<char&>(val)); } StlWrapper() { // } StlWrapper(StlWrapper<value_type> const& /*other*/) { // } template<class T2, class alloc> StlWrapper(const StlWrapper<T2, alloc>& /*other*/) { // } template<class T2> StlWrapper<value_type>& operator=(StlWrapper<T2> const& /*other*/) { return (*this); } bool operator==(const StlWrapper<value_type, allocator>& /*other*/) const { return true; } bool operator!=(const StlWrapper<value_type, allocator>& /*other*/) const { return false; } template<typename otherAllocator> bool operator==(const StlWrapper<value_type, otherAllocator>& /*other*/) const { return false; } template<typename otherAllocator> bool operator!=(const StlWrapper<value_type, otherAllocator>& /*other*/) const { return true; } void deallocate(value_type* ptr, size_type /*unused*/) { allocator::free(ptr); } value_type* allocate(size_type count) { if(count == 1) { return (value_type*)(allocator::alloc()); } return (value_type*)(allocator::alloc(count)); } value_type* allocate(size_type count, const void* /*unused*/) { return (value_type*)(allocate(count)); } void construct(value_type* ptr) { ::new ((void *)ptr) T(); } void construct(value_type* ptr, value_type const& other) { ::new ((void *)ptr) T(other); } #if (defined(_WIN32) && _MSC_VER < 1800) # define SPRAWL_ALLOC_MEMBER_CONSTRUCT( \ TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, CALL_OPT, X2, X3, X4) \ template<class _Objty COMMA LIST(_CLASS_TYPE)> \ void construct(_Objty *_Ptr COMMA LIST(_TYPE_REFREF_ARG)) \ { \ ::new ((void *)_Ptr) _Objty(LIST(_FORWARD_ARG)); \ } _VARIADIC_EXPAND_0X(SPRAWL_ALLOC_MEMBER_CONSTRUCT, , , , ) # undef SPRAWL_ALLOC_MEMBER_CONSTRUCT #else template< typename T2, typename... Args > void construct( T2* ptr, Args&&... args ) { ::new ((void*)ptr) T2(std::forward<Args>(args)...); } #endif template<class T2> void destroy(T2* ptr) { (void)(ptr); ptr->~T2(); } size_t max_size() const { return ((size_t)(-1) / sizeof (T)); } }; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 18645 | brandon_m_bare | Integrated latest version of libsprawl. | ||
#1 | 15089 | brandon_m_bare | First integration of sprawl. | ||
//guest/ShadauxCat/Sprawl/Mainline/memory/StlWrapper.hpp | |||||
#3 | 14783 | ShadauxCat |
Style corrections (placement of const) #review-14784 |
||
#2 | 14216 | ShadauxCat |
-Moved some global sprawl::Strings into local scope in json serialization test because of initialization order issues in the memory allocator on mac. This is a temporary fix, and a real fix will come by making the pool allocator work in explicitly-sized pieces and putting all the code for those pieces into a cpp file. -Fixed a large number of warnings on mac/linux that were exposed by fixes to csbuild -Fixed compile errors on mac due to malloc and alloca not being defined, fixed by #include <stdlib.h> in appropriate places -Fixed mac os x trying to link against pthread erroneously -Provided os x implementation of time library -Fixed compile errors on os x due to std::unordered_map whining about the difference between an allocator that allocates std::pair<key, value> and one that allocates std::pair<key const, value>, which, of course, is that the allocator will be no different at all. -Fixed an actual issue where one unordered_map was allocating only key_type instead of std::pair<key_type, value_type> -Fixed a memory leak where coroutine objects would never be cleaned up because either Yield() or reactivate_() will never return (and thus never clean up their stack memory and thus never release any dynamic memory held in stack objects) depending on the situation - if the function runs to completion, reactivate_() never returns after calling swapcontext(); meanwhile, if the function does not run to completion, Yield() never returns after calling Pause(). This behavior will need to be well-documented because it will affect client-side code as well. Stack memory within a coroutine should not rely on RAII behavior. -Fixed compile failure when creating a StlWrapper with a const value_type #review-14217 |
||
#1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |