Re: [ROOT] Streaming an array whose size is a non-const parameter

From: Brett Viren (bv@bnl.gov)
Date: Fri Jan 31 2003 - 19:48:35 MET


Carlos Muņoz Camacho writes:
 >    I can, but then I need to call the push_back method every time I add an
 > element. As the size of the array is constant and known, I want to
 > allocate memory only once (and eventually re-use it for the next event)

STL vectors can be pre-allocated:

	int siz = 100;
	//...
	std::vector v(siz);
	for (int i = 0; i<100; ++i) v[i] = i;
	

Or, if you don't want to set the size at construction do:

	std::vector v;
	//...
	v.reserve(siz);

-Brett.



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:09 MET