#include <vector>
#include <string>
#include <memory>
#include <iostream>
#include <ctime>
#include <cstdlib>
#define LEN 1000000
char stringlengths[LEN];
int main(void)
{
srand(0);
int totalalloc = 0;
for(int i=0; i<LEN; ++i) {
stringlengths[i] = rand()%16;
totalalloc += stringlengths[i];
}
std::cout << "total string length to be allocated: " << totalalloc << '\n';
int pre, post;
#if 0
{
std::cout << "virtual memory before: ";
std::cin >> pre;
std::unique_ptr<char*[]> ctest(new char*[LEN]);
for(int i=0; i<LEN; ++i)
ctest[i] = new char[stringlengths[i]];
std::cout << "virtual memory after: ";
std::cin >> post;
std::cout << "char* difference of " << (post-pre) << '\n';
for(int i=0; i<LEN; ++i)
delete [] ctest[i];
}
#endif
#if 0
{
std::cout << "virtual memory before: ";
std::cin >> pre;
std::unique_ptr<std::unique_ptr<char[]>[]> ctest(new std::unique_ptr<char[]>[LEN]);
for(int i=0; i<LEN; ++i)
ctest[i].reset(new char[stringlengths[i]]);
std::cout << "virtual memory after: ";
std::cin >> post;
std::cout << "unique_ptr difference of " << (post-pre) << '\n';
}
#endif
#if 1
{
std::cout << "virtual memory before: ";
std::cin >> pre;
std::unique_ptr<std::string[]> ctest(new std::string[LEN]);
for(int i=0; i<LEN; ++i)
ctest[i].resize(stringlengths[i]);
std::cout << "virtual memory after: ";
std::cin >> post;
std::cout << "std::string difference of " << (post-pre) << '\n';
}
#endif
std::cin >> pre;
return 0;
}