Newbie Question Shared Memory Containers/Allocators

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Newbie Question Shared Memory Containers/Allocators

Boost - Users mailing list
Hi everybody, 

how are you?

I am a completely noob when it comes to Boost.  :D But not a noob when it comes to C++. Though, am a bit noobish when it comes to C++14 and beyond :D

I am trying to construct a complex data container, which has a vector of floats, on managed shared memory.

I followed the documentation, added the appropriate headers and made the following declarations:

typedef managed_windows_shared_memory::segment_manager segment_manager_t;
typedef allocator<void, segment_manager_t>  void_allocator;
typedef basic_string<char, std::char_traits<char>, char_allocator> shared_string;
typedef allocator<float, segment_manager_t> float_allocator;
typedef vector<float, float_allocator> float_vector;
typedef allocator<float_vector, segment_manager_t> float_vector_allocator;

class ComplexContainer 
{
shared_string name;
float_vector channelData;

public:
ComplexContainer(const char * name_, const float* data_start, const float* data_end, const void_allocator& void_alloc) :
     name(name_), channelData(data_start, data_end, void_alloc)
   {}

ComplexContainer(const void_allocator& void_alloc) :
   name(void_alloc), channelData(void_alloc)
{}


ComplexContainer() {}


}


but I am getting these errors at compile:

1>D:\Libraries\boost_1_72_0\boost\container\vector.hpp(310,23): error C2512: 'boost::interprocess::allocator<float,segment_manager_t>::allocator': no appropriate default constructor available
1>D:\Libraries\boost_1_72_0\boost\container\vector.hpp(308): message : while compiling class template member function 'boost::container::vector_alloc_holder<boost::interprocess::allocator<float,segment_manager_t>,unsigned __int64,boost::move_detail::integral_constant<unsigned int,2>>::vector_alloc_holder(void) noexcept(false)'
1>D:\Libraries\boost_1_72_0\boost\container\vector.hpp(832): message : see reference to function template instantiation 'boost::container::vector_alloc_holder<boost::interprocess::allocator<float,segment_manager_t>,unsigned __int64,boost::move_detail::integral_constant<unsigned int,2>>::vector_alloc_holder(void) noexcept(false)' being compiled
1>D:\Libraries\boost_1_72_0\boost\container\vector.hpp(779): message : see reference to class template instantiation 'boost::container::vector_alloc_holder<boost::interprocess::allocator<float,segment_manager_t>,unsigned __int64,boost::move_detail::integral_constant<unsigned int,2>>' being compiled

message : see reference to class template instantiation 'boost::container::vector<float,float_allocator,void>' being compiled



That doesn't make a whole lot of sense, since it seems to be referring to the "float_allocator" typedef. But float is not an object, it has no constructor.



Any help would be greatly appreciated!

Thank you!

Da.

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Newbie Question Shared Memory Containers/Allocators

Boost - Users mailing list
On 02/02/2020 7:07, Da Xu via Boost-users wrote:

> Hi everybody,
>
> how are you?
>
> I am a completely noob when it comes to Boost.  :D But not a noob when
> it comes to C++. Though, am a bit noobish when it comes to C++14 and
> beyond :D
>
> I am trying to construct a complex data container, which has a vector of
> floats, on managed shared memory.
>
> I followed the documentation, added the appropriate headers and made the
> following declarations:
>
> typedef managed_windows_shared_memory::segment_manager segment_manager_t;
> typedef allocator<void, segment_manager_t>  void_allocator;
> typedef basic_string<char, std::char_traits<char>, char_allocator>
> shared_string;
> typedef allocator<float, segment_manager_t> float_allocator;
> typedef vector<float, float_allocator> float_vector;
> typedef allocator<float_vector, segment_manager_t> float_vector_allocator;
>
> class ComplexContainer
> {
> shared_string name;
> float_vector channelData;
>
> public:
> ComplexContainer(const char * name_, const float* data_start, const
> float* data_end, const void_allocator& void_alloc) :
>       name(name_), channelData(data_start, data_end, void_alloc)
>     {}
>
> ComplexContainer(const void_allocator& void_alloc) :
>     name(void_alloc), channelData(void_alloc)
> {}
>
>
> ComplexContainer() {}
>
>
> }

Hi,

1) shared_string also needs char_allocator as a second parameter.
2) a float vector does not expect a void_allocator, but a
float_vector_allocator

Best,

Ion
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users