i have the following struct:
struct Message {
Agent *_agent;
double _val;
};
and the following Ptrs array:
typedef Message* MessageP;
MessageP *_msgArr;
_msgArr = new MessageP[MAX_MESSAGES];
this is the method that inserts a Message to the array:
void Timing::AddMessage(Agent * const agentPtr, double val) {
MessageP msgPtr = new Message;
assert(msgPtr != 0);
//assign values:
(*msgPtr)._agent = agentPtr;
(*msgPtr)._val = val;
//add to messages array:
assert(_msgArr != 0 && _waitingMsgs<MAX_MESSAGES);
_msgArr[_waitingMsgs] = msgPtr;
_waitingMsgs++;
}
My question is about the deletion of this array. I would like to delete the array and all allocated structs. if i write:
delete [] _msgArr
will this delete also each allocated struct or will free only the allocated memory for the array?
Is the correct way is to go over the entire array with a for loop and write
delete _msgArr[i]
and at last wite delete [] _msgArr to delete the allocated array ?
thanks!
std::vectororstd::deque?