jeudi 25 février 2016

Improve storage capacity / performance of std::vector

I am building a modelling software I had a few questions about how to get the best performance ?

1) Should I use std::vector<class> or std::vector<class*> ? My class is quite complicated / big , and I think using the second option is better , as since std::vector tries to allocate memory contiguously and there might not be a contiguous block of memory to store a million class , but when I just store pointers , the classdoes not have to be stored contiguously only the pointers have to stored and the computer might have space to do this. Is this reasoning correct ?

2) As I said I will have millions of class , ( for proper simulation I will need > billion of the class ) is inhertiance a smart thing to use here ? For my simulation , there are multiple different types which inherits from the same base class,

class A - class B 
        - class C
        - class D 

Should I avoid inheritance as I keep hearing that there is a performance penalty for using inheritance ?

3) Also how do I store all these different class in a std::vector ? Can a std::vector or std::vector store class B , class C , class D which all inherit from the base class ?

4) In the previous version of the program , I used multi threading by making the different process handle different sections of the std::vector , is there a better way to do the threading ?

5) Should I use smart pointers ? Since I have so many objects , will they degrade performance ?

I am in the planning stage and any help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire