Home

Hi,

I have a vector<char*>

vector<char *> arguments;

and I have code to free memory (from example in effective stl):

struct DeleteObject {

template<typename T>
void operator()(const T* ptr) const {
delete ptr;
}
};

for_each(arguments.begin(), arguments.end() , DeleteObject());

arguments.clear();

My question is I currently is doing this:
// allocate memory on the heap
char* arg2 = new char[20];
memset (arg2, '\0', 20);
memcpy( arg2, "dummy", strlen("dummy") );
arguments.push_back(arg2);

I wonder if I can simplify by doing this:
arguments.push_back("dummy");

But if i do this, where does the memory allocated? And If I can still
use this:

for_each(arguments.begin(), arguments.end() , DeleteObject());

to free all memory used by arguments?

Thank you.

previous
next

CaFeCONF 2007 6tas. Conferencias Abiertas de Software Libre y GNU/Linux
Re: using sstream to read a vector<string>
Re: How to call module functions inside class instance functions?
Re: Pointer vs Reference
Re: A way to re-organize a list
Bajki
download
www.malopolaki.darmowefora.pl
Catering PoznaƄ
ecommerce