As far as I understand push_back() of std::deque copies the data I put in. So, when I put in reference to dynamic data (such as to a dynamic bytearray or std::vector) it copies only the reference to it. Now I try to understand if I have to delete/free my dynamically allocated data before pop_back() from std::deque? C++11 is given. Hope someone can help me out! Below I have my two scenarios in as code examples:
Scenario I:
typedef struct mystruct{
uint8_t* data;
//other fields may be here
} mystruct_t;
mystruct_t my;
my.data = new uint8_t[3];
my.data[0] = 'A';
my.data[1] = 'B';
my.data[2] = 'C';
std::deque<mystruct_t> d;
d.push_back(my);
// ...
// Need to delete/free data here, before d.pop_back()?
d.pop_back();
Scenario II:
typedef struct mystruct{
std::vector<uint8_t> data;
// other fields may be here
} mystruct_t;
mystruct_t my;
my.data.push_back('A');
my.data.push_back('B');
my.data.push_back('C');
std::deque<mystruct_t> d;
d.push_back(my);
// ...
// Need to delete/free data here, before d.pop_back()?
d.pop_back();