Browse Source

registry: allocate_shared pools to further improve the use of the allocator

Michele Caini 3 years ago
parent
commit
534dc7e7b7
1 changed files with 3 additions and 2 deletions
  1. 3 2
      src/entt/entity/registry.hpp

+ 3 - 2
src/entt/entity/registry.hpp

@@ -313,7 +313,7 @@ class basic_registry {
         auto &cpool = pools[id];
 
         if(!cpool) {
-            cpool.reset(new storage_for_type<Type>{get_allocator()});
+            cpool = std::allocate_shared<storage_for_type<std::remove_const_t<Type>>>(get_allocator(), get_allocator());
             cpool->bind(forward_as_any(*this));
         }
 
@@ -1506,7 +1506,8 @@ private:
     context vars;
     entity_type free_list;
     std::vector<entity_type, allocator_type> epool;
-    dense_map<id_type, std::unique_ptr<base_type>, identity, std::equal_to<id_type>, typename alloc_traits::template rebind_alloc<std::pair<const id_type, std::unique_ptr<base_type>>>> pools;
+    // std::shared_ptr because of its type erased allocator which is useful here
+    dense_map<id_type, std::shared_ptr<base_type>, identity, std::equal_to<id_type>, typename alloc_traits::template rebind_alloc<std::pair<const id_type, std::shared_ptr<base_type>>>> pools;
     std::vector<group_data, typename alloc_traits::template rebind_alloc<group_data>> groups;
 };