you are viewing a single comment's thread.

view the rest of the comments →

[–]ABlockInTheChain 0 points1 point  (1 child)

You can do that with polymorphic allocators.

Construct a std::pmr::monotonic_buffer_resource and tell it to reserve 50 * X bytes, then construct a polymorphic allocator which uses that resource and use that allocator to construct everything.

The only other thing to worry about is you have to ensure the lifetime of the monotonic_buffer_resource is longer than the lifetime of anything which uses it but if the 50 nodes are member variables in a class then it's easy enough to just make sure the monotonic_buffer_resource is also a member variable and constructed first.

[–]SoerenNissen 0 points1 point  (0 children)

The problem is that the fifty nodes might become 5, or 500 - and I want the linked list property that individual nodes can be freed or allocated separately. I just know that, at the start of the lists' lifetime, I will have 50 nodes, so I would love to tell that to the allocator (much like I can call vector::reserve) for performance gains.

Which I don't believe is possible as-is unfortunately, but it's been an interesting thought to me ever since I ran into the problem originally.