Category : allocator

Context So I have a parser which can parse many different types of objects. I parse one file per object type using a function that has this typing: template <typename T> std::vector<T *> parseFeaturesfromFile(std::string) And when creating an object World, I use this function like this (in the constructor of World): const std::vector<C_type *> c_types ..

Read more

I am reading some C++ code and specifically trying to understand a customised container. The container has following the template parameters: template<typename T, typename Alloc> class container{ … }; Where T is the type of data like float or int. The Alloc is the allocator and could be one of the standard libraries ones. Within ..

Read more

Autogenerated ROS (Robot Operating System) message C++ header files contain typedefs like this: typedef ::std_msgs::Header_<std::allocator<void> > Header; What does std::allocator<void> mean here? Why is the template type void? Here is the documentation for std::allocator<>: https://www.cplusplus.com/reference/memory/allocator/ https://en.cppreference.com/w/cpp/memory/allocator Here is the example autogenerated file to look at: http://docs.ros.org/en/electric/api/std_msgs/html/msg__gen_2cpp_2include_2std__msgs_2Header_8h_source.html. That first line above is line 116. This is ..

Read more

I have the following toy code that works: #include <cstdlib> #include <vector> template <typename T> struct Dummy { using value_type = T; using size_type = size_t; using difference_type = ptrdiff_t; using pointer = value_type*; using const_pointer = const value_type*; using reference = value_type&; using const_reference = const value_type&; Dummy() = default; Dummy(const Dummy&) = default; ..

Read more

In a talk from 2015 Andrei Alexandrescu outlines some atrocities of the std::allocator interface, shortly highlighting how it’s not in fact about allocation and proposing a different way of thinking about these allocators that would make them more usable and modular. Or, to quote from the description: std::allocator has an inglorious past, murky present, and ..

Read more

I have started using pmr::allocators in my project, and I have seen a lot of performance boost and advantage from using them. I use allocator very similar to what I show int the simple example below: #include <array> #include <boost/container/flat_map.hpp> #include <cassert> #include <iostream> #include <memory_resource> #include <string> #include <vector> struct MessageBody { using map_t ..

Read more