-
I'm interested in iceoryx_hoofs and I have few questions. I understood the goals of iceoryx_hoofs is to remove dynamic allocation and use fixed static memory. When I saw the iox::cxx::vector and api emplace_back, There are few point to use dynamic allocation like the followings. {code} There is a code to use 'new', I think this is the code using heap. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@givesun Here you are mistaken.
The difference is subtle but in this case we provide the memory location in the first bracket new (&at(m_size++)) T(std::forward(args)...); If we would allocate this on the heap the call would look like: new T(std::forward(args)...); If you would like to dive deeper into placement new take a look at this article: https://en.cppreference.com/w/cpp/language/new#Placement_new |
Beta Was this translation helpful? Give feedback.
@givesun Here you are mistaken.
new
has in the end to options:The difference is subtle but in this case we provide the memory location in the first bracket
(&at(m_size++))
and then call the constructor ofT
withT(std::forward(args)...)
which results inIf we would allocate this on the heap the call would look like:
new T(std::forward(args)...);
If you would like to dive deeper into placement new take a look at this article: https://en.cppreference.com/w/cpp/language/new#Placement_new