Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Jul 2012
Offline Last Active Today, 10:58 AM

Posts I've Made

In Topic: Getting direct acces to vector<unique_ptr<My_Class>> but ther...

16 August 2014 - 06:03 PM

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
short myVecID;
short TargetObjectVecID;
bool isInUse;
std::vector<My_Class> listObject;

Efficiently i can access it directly via

Object o;//Object in use

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;
//Adding object
if(listObjectEmptyPos.size() > 0)
   listObject[listObjectEmptyPos.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.

In Topic: Getting direct acces to vector<unique_ptr<My_Class>> but ther...

12 August 2014 - 09:55 AM


I feel that map will be slow.
premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

- Donald Knuth


I agree, but if i am making something i will make it right from start, instead of spending time redoing it when i find out its slow, when i know it will be slow, chances that compiler would optimize are close to none, but there may be something out of my knowledge so profiling would be the choice, i just don't have time and i am certain that doing vector thingy i said would provide me with great performance and probably 10-15% more work, which ends up in 10 minute of coding when i know exactly what i am doing or what i want want.

In Topic: Getting direct acces to vector<unique_ptr<My_Class>> but ther...

11 August 2014 - 05:56 PM

I feel that map will be slow.

Thinking about how many times i will have to search for object. Having a vector and removing peaces from it is also a downside thus i decided:
I will have vector in which i will hold all data. When i want object removed, i will just release its pointer. and save the vector position as empty.
The issue: In case allot of objects get removed and little are added, the vector starts to stall, because it never sizes down, but it will provide me with possibility of easy access, and i can make something that will check to sort it when 33% of it is just empty objects

int VecID = 921;
std::vector<std::unique_ptr<My_Class>> list;
std::vector<int> listEmptyPos;
//Adds 921 to listEmptyPos, and releases pointer in list

I really need it to be fast, the downfall compared to gain is unmatched to using map when size is always gonna be 1k+ of objects.


Thanks on suggestions, i posted above my solution.

In Topic: 2d drawing pipeline, how to get good performance, i just figured out i got no...

09 August 2014 - 08:37 PM

Thank you on suggestions.

In Topic: Unit follow a path, tutorials, examples please

01 August 2014 - 03:50 PM

thank for replay