| | |
optimize code
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2006
Posts: 7
Reputation:
Solved Threads: 0
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
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
- code optimization ... (C++)
- Why am I getting this output (C++)
- code optimization (C)
- Optimize this code? (ASP)
- Problem with objects having objects as attributes (C++)
- Ram... (Game Development)
Other Threads in the C++ Forum
- Previous Thread: variance calc incorrect why?
- Next Thread: Need help to edit fin & fout files output
Views: 1164 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





