Getting direct acces to vector<unique_ptr<My_Class>> but there are these factors...

Started by
7 comments, last by BaneTrapper 9 years, 8 months ago

Ive tested on paper and code, vector provided allot desired performance which was unnoticeable in % cpu usage 0-1%, meanwhile map cpu usage was noticeable ~5.

But vector at worst case used ~15% more memory usage then map, which with 1000objectts with ~200bytes of data each end up with 150*200, 30kilobytes... unnoticeable memory vise because main platform is PC.

With vector i use this:

Class My_Class
{
pubic:
short myVecID;
short TargetObjectVecID;
bool isInUse;
}
std::vector<My_Class> listObject;

Efficiently i can access it directly via

Object o;//Object in use
listObject[o.TargetObjectVecID].Something();

instead of looping and searching trough the whole map if i where to use one, to match the ID.

How i manage deleting objects and adding object

//Concider My_Class from above
std::vector<My_Class> listObject;
std::vector<short> listObjectEmptyPos;
 
//Erasing object
listObject[object_id_to_erase].isInUse = false;
listObjectEmptyPos.push_back(object_id_to_erase);
 
//Adding object
if(listObjectEmptyPos.size() > 0)
   listObject[listObjectEmptyPos.back()] = NewMy_Object;
   listObjectEmptyPos.pop_back();
else
   listObject.push_back(NewMy_Object);

I am inexperienced in std::map usage, but vector provides me with better cpu usage in theory and practice, and memory is no issue. So i chose vector over map.

This topic is closed to new replies.

Advertisement