Two part question illustrated by following code
#include <memory>
#include <vector>
#include <boost/pool/object_pool.hpp>
struct Foo {
Foo(int i) : _i(i) {}
void* operator new(size_t) = delete; // ***
int _i;
};
using FooHandle = std::unique_ptr<Foo>;
struct Bar {
Foo* addFoo(int i)
{
Foo* ptr = new (_fooPool.malloc()) Foo(i); // 111
return FooHandle(ptr,
&boost::object_pool<Foo,
boost::default_user_allocator_new_delete>::destroy); // 222
}
boost::object_pool<Foo> _fooPool;
};
I am trying to assure that 1) objects of type Foo are allocated and owned only by objects of type Bar, 2) they are stored in pools, and 3) they are accessed via unique pointers.
Using Visual Studio compiler I run into following problems 1) If I delete default operator new (line marked with ***) then placement new (line marked with 111) does not compile. Am I doing something wrong or is it VS limitation?
2) I imagine that in order to make a proper unique_ptr that was allocated in a pool I need to supply access to pool deleter. Line marked as 222 is my attempt to do just that. Compiler does not accept it either. What is the correct syntax?
Aucun commentaire:
Enregistrer un commentaire