Edit: Corrected "s1" and "s2" to "a1" and "a2" in the example code:
Phil Bouchard wrote:
An easy way to use a custom allocator is by deriving from block<>:
template <typename T>
struct userblock : public block
{
};
And then you can instantiate using:
proxy_ptr<int> x(new userblock<int>());
Phil, how would you do the following, with your block pointer:
small_object_allocator_state a1(buffer1, size1);
small_object_allocator_state a2(buffer2, size2);
std::vector
v1(small_object_allocator(a1));
std::shared_ptr<double> p1 =
std::allocate_shared(small_object_allocator(a1));
std::set l1(small_object_allocator(a2));
std::shared_ptr<bool> p2 = std::allocate_shared(small_object_allocator(a2));
In this example, consider small_object_allocator<> a _stateful_ C++
allocator that can be used with any existing C++ allocator-aware
standard library tools (like vector, set, allocate_shared).
[ As its name indicates, assume it attempts to use memory from the
buffer specified in its state, up to the size specified in its state,
for allocations if possible, and after that space is extinguished, it
resorts to normal dynamic allocation. i.e. Your typical "stack
allocator". ]
In the example above, v1 (vector) and p1 (shared_ptr) both use a1
state, while s1 (set) and p2 (shared_ptr) both use a2 state
If I want to use block_ptr in that style above, with a
"small_object_allocator" instance constructed from a
"small_object_allocator_state" like "a1", _without_ having to write
any additional classes, what would the line look like?
proxy_ptr<int> p3(new block(/*
some place to specify 'a1' here? */));
And then are you guaranteeing that 'new' expression in that
construction of proxy_ptr will also use a 'small_object_allocator{a1}'
allocator instance for dynamic allocation, and not '::operator
new(std:;size_t)'?