/************************************************************************************
 *	STL Vector Memory Exmaple
 *	-----------------------------
 *	code by : bobby anguelov - banguelov@cs.up.ac.za
 *	downloaded from : takinginitiative.wordpress.org
 *
 *	code is free for use in whatever way you want, however if you work for a game
 *	development firm you are obliged to offer me a job :P (haha i wish)
 ************************************************************************************/

//standard libraries
#include <iostream>
#include <vector>

//use standard namespace
using namespace std;

int main()
{
	//create a vector
	vector<double*> t;	
	cout << endl << "Size of vector after being created: " << t.size() << endl;
	cout << "Bytes allocated to vector when created: " << t.capacity() << endl;

	//fill vector with arrays of values
	for (int i=0; i < 20000; i++)
	{	
		t.push_back(new double[16]);		
	}

	cout << endl << "Size of vector after being filled: " << t.size() << endl;
	cout << "Bytes allocated to vector after being filled with values: " << t.capacity() << endl;

	//free all allocated memory in vector and delete all vector elements
	for ( int i=0; i < t.size(); i++ ) delete[] t[i];
	t.clear();
	
	cout << endl << "Size of vector after deletion: " << t.size() << endl;
	cout << "Bytes allocated to vector after deletion : " << t.capacity() << endl;

	//swap vector with blank vector
	vector<double*>().swap(t);

	cout << endl << "Size of vector after swap: " << t.size() << endl;
	cout << "Bytes allocated to vector after swap : " << t.capacity() << endl;
	
	cout << endl << "-- END OF PROGRAM --" << endl;
	char c; cin>> c;
	return 0;
}

