Hello, I've been experimenting with STD::Vector, And I've been trying to find the most efficient way to delete a large number of items from an Std::Vector, In the fastest way possible.
This Is the program I have been writing:
#include<iostream>
#include <memory>
#include <vector>
using namespace std;
struct SmallObject1
{
int a[256];
};
int main()
{
char a;
typedef vector<shared_ptr<SmallObject1>> ObjectList;
ObjectList * list1 = new ObjectList();
cout << "Allocate 65536, objects Lol!" << "\n";
for(unsigned int i = 0; i < 65536; i++)
{
SmallObject1 * smallObject1 = new SmallObject1;
shared_ptr<SmallObject1> a(smallObject1);
list1->push_back(a);
}
cout << "Allocated! Try Again?" << "\n";
/*while(list1.size() != 0)
{
list1.pop_back();
}*/
//list1->clear();
delete list1;
list1 = new ObjectList;
cout << "Deleted....";
for(unsigned int i = 0; i < 65536; i++)
{
SmallObject1 * smallObject1 = new SmallObject1;
shared_ptr<SmallObject1> a(smallObject1);
list1->push_back(a);
}
cout << "COMPLETE!!!1!!!";
while(1)
{
}
return 0;
}
If I were Writing a video game, and I was transitioning to another level, I Would want to remove the objects for Level 1 from the list as Fast As Possible. However, All the methods I've tried seemed to result into waiting a couple of seconds for the objects to be deleted.
I'm thinking of removing all the objects on a separate thread, And allocating the New objects on the main thread, in a Separate list, and then after the objects are removed, then append the list to the main list. But I'm not sure if it will work, and I know next to nothing about Multi-Threading :( .
Anyways, I was wondering if anyone has any alternative solutions to this dillema, as I can't seem to find a faster method.