[Block.Pointer][Container] List node allocator
I've refactored most of the internal algorithms of block_ptr<> and now
it is much more robust. The following example works pretty well:
https://github.com/philippeb8/block_ptr/blob/master/example/block_ptr_test1....
The next step is to support Boost.Containers:
https://github.com/philippeb8/block_ptr/blob/master/example/block_ptr_test2....
But after debugging the code it looks like the allocator is not used to
instantiate the nodes and I do not see how it is used by looking at the
code:
template
On 03/01/2016 12:00 AM, Phil Bouchard wrote:
I've refactored most of the internal algorithms of block_ptr<> and now it is much more robust. The following example works pretty well: https://github.com/philippeb8/block_ptr/blob/master/example/block_ptr_test1....
The next step is to support Boost.Containers: https://github.com/philippeb8/block_ptr/blob/master/example/block_ptr_test2....
But after debugging the code it looks like the allocator is not used to instantiate the nodes and I do not see how it is used by looking at the code:
template
struct list_node : public list_hook<VoidPointer>::type { private: //list_node(); public: typedef T value_type; typedef typename list_hook<VoidPointer>::type hook_type;
T m_data;
T &get_data() { return this->m_data; }
const T &get_data() const { return this->m_data; } };
Am I missing something?
Sorry I forgot that the header node is instantiated on the stack. Smart pointers pointing to objects on the stack doesn't work so therefore modifications to the Container API will be needed to support smart pointers.
On 03/01/2016 08:14 AM, Phil Bouchard wrote:
Sorry I forgot that the header node is instantiated on the stack. Smart pointers pointing to objects on the stack doesn't work so therefore modifications to the Container API will be needed to support smart pointers.
Also once that works I could define some typedefs:
namespace boost
{
namespace container
{
template <typename T>
using block_list<T> = list
On March 1, 2016 8:14:20 AM EST, Phil Bouchard
Sorry I forgot that the header node is instantiated on the stack.
Do you mean that the header node is part of the container object? If so, it may be allocated on the stack or the free store depending upon how the container itself was allocated. ___ Rob (Sent from my portable computation engine)
On 03/01/2016 03:23 PM, Rob Stewart wrote:
On March 1, 2016 8:14:20 AM EST, Phil Bouchard
wrote: Sorry I forgot that the header node is instantiated on the stack.
Do you mean that the header node is part of the container object? If so, it may be allocated on the stack or the free store depending upon how the container itself was allocated.
Yes exactly.
On 01/03/2016 14:14, Phil Bouchard wrote:
But after debugging the code it looks like the allocator is not used to instantiate the nodes and I do not see how it is used by looking at the code:
template
struct list_node : public list_hook<VoidPointer>::type { private: //list_node(); public: typedef T value_type; typedef typename list_hook<VoidPointer>::type hook_type;
T m_data;
T &get_data() { return this->m_data; }
const T &get_data() const { return this->m_data; } };
Am I missing something?
A node is created using allocator_traits::construct, which is what the standard mandates.
Sorry I forgot that the header node is instantiated on the stack. Smart pointers pointing to objects on the stack doesn't work so therefore modifications to the Container API will be needed to support smart pointers.
Supporting embedded end pointers is not only an option, but the choice of most STL implementations. It makes default constructors nothrow and improves performance. Any smart pointer should support pointing to those end nodes or it's just broken for STL-like containers. Best, Ion
On 03/01/2016 04:27 PM, Ion Gaztañaga wrote:
On 01/03/2016 14:14, Phil Bouchard wrote:
Sorry I forgot that the header node is instantiated on the stack. Smart pointers pointing to objects on the stack doesn't work so therefore modifications to the Container API will be needed to support smart pointers.
Supporting embedded end pointers is not only an option, but the choice of most STL implementations. It makes default constructors nothrow and improves performance. Any smart pointer should support pointing to those end nodes or it's just broken for STL-like containers.
You're right. I think there's a way for block_ptr<> to support weak references and I will get rid of the strange pointer-on-the-heap initialization optimization at the same time. Regards, -Phil
On 03/01/2016 06:20 PM, Phil Bouchard wrote:
On 03/01/2016 04:27 PM, Ion Gaztañaga wrote:
Supporting embedded end pointers is not only an option, but the choice of most STL implementations. It makes default constructors nothrow and improves performance. Any smart pointer should support pointing to those end nodes or it's just broken for STL-like containers.
You're right. I think there's a way for block_ptr<> to support weak references and I will get rid of the strange pointer-on-the-heap initialization optimization at the same time.
I just added support for weak references but I still have problems with Boost containers: https://github.com/philippeb8/block_ptr/blob/master/example/block_ptr_test2.... -Phil
On 03/01/2016 10:40 PM, Phil Bouchard wrote:
On 03/01/2016 06:20 PM, Phil Bouchard wrote:
On 03/01/2016 04:27 PM, Ion Gaztañaga wrote:
Supporting embedded end pointers is not only an option, but the choice of most STL implementations. It makes default constructors nothrow and improves performance. Any smart pointer should support pointing to those end nodes or it's just broken for STL-like containers.
You're right. I think there's a way for block_ptr<> to support weak references and I will get rid of the strange pointer-on-the-heap initialization optimization at the same time.
I just added support for weak references but I still have problems with Boost containers: https://github.com/philippeb8/block_ptr/blob/master/example/block_ptr_test2....
Ok now everything works!! https://github.com/philippeb8/block_ptr/blob/master/example/block_ptr_test2.... So now block_ptr<> is Boost.Container compliant! I still need to fix an issue but it's moving forward! Thanks, -Phil
participants (3)
-
Ion Gaztañaga
-
Phil Bouchard
-
Rob Stewart