diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp index 4d20ed1..d2b9aa7 100644 --- a/src/core/pool_type.hpp +++ b/src/core/pool_type.hpp @@ -68,6 +68,38 @@ struct PoolBase { PoolBase(const PoolBase &other); }; + +/** + * A STL allocator that doesn't construct or destruct elements, but just memcpy's them. + * @tparam T Type to allocate. + */ +template +struct MemCpyAllocator { + typedef T value_type; + typedef T *pointer; + typedef const T *const_pointer; + typedef T& reference; + typedef const T& const_reference; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + /** Convert this type to MemCpyAllocator. */ + template struct rebind { typedef MemCpyAllocator other; }; + + /** Allocate memory for several elements. */ + pointer allocate(size_type n, const void *hint = 0) { return MallocT(n); } + /** Free memory of several elements. */ + void deallocate(pointer p, size_type n) { free(p); } + /** Copy construct a single item. */ + void construct(pointer p, const_reference t) { MemCpyT(p, &t); } + /** Destruct a single item. */ + void destroy(pointer p) {} + + /** Estimate maximum array size. */ + size_t max_size() const { return ((size_type)(-1) / sizeof(value_type)); } +}; + /** * Base class for all pools. * @tparam Titem Type of the class/struct that is going to be pooled @@ -144,6 +176,8 @@ struct Pool : PoolBase { */ template *Tpool> struct PoolItem { + typedef ::MemCpyAllocator MemCpyAllocator; + Tindex index; ///< Index of this pool item /** diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp index df4aa37..6f001bd 100644 --- a/src/saveload/engine_sl.cpp +++ b/src/saveload/engine_sl.cpp @@ -48,7 +48,7 @@ SLE_END() }; -static std::vector _temp_engine; +static std::vector _temp_engine; Engine *GetTempDataEngine(EngineID index) {