-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Begone realloc #966
Begone realloc #966
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't run it yet. Some city_report_specs
code could be simplified further by declaring variables inside loops and using auto
, but the reduction in manual memory management is already a significant improvement.
@@ -33,8 +33,7 @@ void ai_traits_init(struct player *pplayer) | |||
{ | |||
enum trait tr; | |||
|
|||
pplayer->ai_common.traits = static_cast<ai_trait *>(fc_realloc( | |||
pplayer->ai_common.traits, sizeof(struct ai_trait) * TRAIT_COUNT)); | |||
pplayer->ai_common.traits = std::vector<ai_trait>(TRAIT_COUNT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be ever resized. TRAIT_COUNT
is 3 and ai_trait
is just two int
s. Would this make more sense as a std::array<ai_trait, TRAIT_COUNT>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was considering the same, also we have waay too much ram these days to have a lot more traits still in stack, Ended up doing the same in heap because I thought the difference would be negligible, and array didnt have clear.
client/gui-qt/cityrep.cpp
Outdated
@@ -219,24 +219,23 @@ bool city_model::setData(const QModelIndex &index, const QVariant &value, | |||
QVariant city_model::headerData(int section, Qt::Orientation orientation, | |||
int role) const | |||
{ | |||
struct city_report_spec *spec = city_report_specs + section; | |||
struct city_report_spec spec = city_report_specs[section]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: const auto &
I did run for 200 turns with ASAN and checked the cityreport with the client to see. Seemed to work for me. |
We are only reading from spec and not modifying it.
Changed a few easy reallocs to vectors