1,075,703 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Posts by ChaseRLewis Contributing to Articles being Marked Solved

When a vector is declared to have a certain number of things such as you init it to size(10000) it's very inefficient to init it with a for loop. Instead you can take a reference pointer to the first member than ZeroMemory it for it's size which is much quicker. Keep in mind this only works well if you have added/removed things. After that you have to worry because internally I believe pushing and erasing keeps items as a linked list but I never really have looked into it.

Overall roshi covered everything else. Though I don't see much advantage to using this over the raw std::vector<double>. Also if your worried about long lists and don't have concurrency issues declaring the size as a int before hand can save you some cycles as compilers typically don't deal with for loops and inline functions very well.

ZeroMemory(&m_vector[0],m_vector.size()*sizeof(double));

//same as above
memset(&m_vector[0],0,m_vector.size()*sizeof(double));
ChaseRLewis
Junior Poster in Training
78 posts since Nov 2009
Reputation Points: 7
Solved Threads: 2
Skill Endorsements: 0
int main()
{
Program();
while(Restart())
{
Program();
}
return 0;
}

void Program()
{
Program code ....
}

bool Restart()
{
code to get bool .... 
}
ChaseRLewis
Junior Poster in Training
78 posts since Nov 2009
Reputation Points: 7
Solved Threads: 2
Skill Endorsements: 0
 
© 2013 DaniWeb® LLC
Page rendered in 0.0369 seconds using 2.46MB