diff --git a/include/libipc/mem/container_allocator.h b/include/libipc/mem/container_allocator.h index 4087b00..97b8449 100644 --- a/include/libipc/mem/container_allocator.h +++ b/include/libipc/mem/container_allocator.h @@ -63,26 +63,18 @@ public: pointer allocate(size_type count) noexcept { if (count == 0) return nullptr; if (count > this->max_size()) return nullptr; - if (count == 1) { - return mem::$new(); - } else { - void *p = mem::alloc(sizeof(value_type) * count); - if (p == nullptr) return nullptr; - for (std::size_t i = 0; i < count; ++i) { - std::ignore = ipc::construct(static_cast(p) + sizeof(value_type) * i); - } - return static_cast(p); - } + // Allocate raw memory without constructing objects + // Construction should be done by construct() member function + void *p = mem::alloc(sizeof(value_type) * count); + return static_cast(p); } void deallocate(pointer p, size_type count) noexcept { if (count == 0) return; if (count > this->max_size()) return; - if (count == 1) { - mem::$delete(p); - } else { - mem::free(ipc::destroy_n(p, count), sizeof(value_type) * count); - } + // Deallocate raw memory without destroying objects + // Destruction should be done by destroy() member function before deallocate + mem::free(p, sizeof(value_type) * count); } template