943,843 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1502
  • C++ RSS
Sep 28th, 2006
0

optimize code

Expand Post »
Hi can anny one help me out optimizing the follwing issue:
A C++ class has the following member:
int status_[75];
During performance analysis it was found out
that the class (its object) was performing unsatisfactorily
making it a necessary candidate for optimization.
The following additional information was also found out
*) Each element of the status_ array assumes only the
following 4 values: -1, 0, 1, 2
*) The bulk of the time was spent in loops like:
for(size_t i=0; i != 75; ++i) {
if(status_[i] == 1) {
// do something...
}
}
*) The set of elements of the status_ array that assume a particular
value is sparse making the above loop inefficient.
Assume that 0 is the default value.
*) The status_ array is updated at places scattered throughout the code
making it difficult to rewrite. However, a particular element
is updated only through a statement like
status[i] = -1;


Please Code an algorithm if possible

Thanks & Regards




Similar Threads
Reputation Points: 18
Solved Threads: 0
Newbie Poster
Ajay Raj is offline Offline
7 posts
since Sep 2006
Sep 28th, 2006
0

Re: optimize code

Try to write it on your own and when you have some code than we'll help you about the optimisation
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: variance calc incorrect why?
Next Thread in C++ Forum Timeline: Need help to edit fin & fout files output





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC