View Issue Details

IDProjectCategoryView StatusLast Update
0005593The Dark ModCodingpublic23.04.2021 05:29
Reporterstgatilov Assigned Tostgatilov  
PrioritylowSeveritytrivialReproducibilityhave not tried
Status resolvedResolutionfixed 
Product VersionTDM 2.09 
Target VersionTDM 2.10Fixed in VersionTDM 2.10 
Summary0005593: idList::Clear refactoring
DescriptionWe decide to do the following changes:
  idList::Clear drops all elements but does not delete them
  idList::ClearFree deletes all elements along with memory buffer
TagsNo tags attached.

Activities

stgatilov

stgatilov

21.04.2021 15:14

administrator   ~0013890

I have underestimates the amount of code and how popular Clear is =)
It took me two evenings to get through all of idList::Clear usages.

I have seen a lot of code which calls Clear when it is not necessary:
  1) clearing default-constructed idList member in class constructor
  2) clearing idList member in class destructor
  3) clearing local idList variable immediately after declaring it (with default constructor called)
No idea why.

The general policy was to use Clear (non-freeing) everywhere, except for:
  1) Use ClearFree in Shutdown / FreeXXX methods
  2) Use ClearFree for lists which contain std::shared_ptr inside (I'd rather prefer to NOT have such stuff in game code)
  3) Use ClearFree For global variables
  4) Sometimes it is also used when list survives for some time, but is obviously never used again...
stgatilov

stgatilov

21.04.2021 15:26

administrator   ~0013891

There are quite a lot of classes which have "Clear" method in game code too.
Initially, I tried to rename them to ClearFree if they do free memory.
But it only makes the code more complicated, plus there is no uniformity there anyway.

So I'll better enforce the strict Clear/ClearFree policy for idlib containers, but leave other Clear methods with their original names.
stgatilov

stgatilov

21.04.2021 16:56

administrator   ~0013892

Committed the changes:
  r9296. idList now has Clear and ClearFree methods.
  r9297. Reviewed all calls to idList::Clear, replaced some of them with ClearFree.
The second commit is pretty massive.

Interestingly, nothing broke even with commit 9296 alone.
The changes of 9297 are done in order to "do things right" (at least try to).
nbohr1more

nbohr1more

22.04.2021 02:22

developer   ~0013893

Linux compile is broken:

/tdm_src/trunk/game/ai/EAS/EAS.cpp:37:20: error: cannot bind non-const lvalue reference of type ‘std::vector<std::shared_ptr<eas::ClusterInfo> >&’ to an rvalue of type ‘eas::tdmEAS::ClusterInfoVector {aka std::vector<std::shared_ptr<eas::ClusterInfo> >}’
  _clusterInfo.swap(ClusterInfoVector());
                    ^~~~~~~~~~~~~~~~~~~

/tdm_src/trunk/game/ai/EAS/EAS.cpp:38:25: error: cannot bind non-const lvalue reference of type ‘std::vector<std::shared_ptr<eas::ElevatorStationInfo> >&’ to an rvalue of type ‘eas::tdmEAS::ElevatorStationVector {aka std::vector<std::shared_ptr<eas::ElevatorStationInfo> >}’
  _elevatorStations.swap(ElevatorStationVector());
                         ^~~~~~~~~~~~~~~~~~~~~~~
stgatilov

stgatilov

22.04.2021 03:14

administrator   ~0013894

Fixed compile error in svn rev 9298.
nbohr1more

nbohr1more

22.04.2021 04:56

developer   ~0013895

Thank you!

Thus far everything appears to be stable. No crashes or anomalies in any complex missions I've fiddled with.
stgatilov

stgatilov

22.04.2021 14:50

administrator   ~0013896

Last edited: 22.04.2021 15:22

Next commit (svn rev 9299) is cleaning idHashIndex methods.
Now Clear does not delete buffers, while ClearFree do free all memory.

svn rev 9300 is about reviewing clearing idDict-s.
stgatilov

stgatilov

22.04.2021 17:36

administrator   ~0013897

Now idStr follows the trend.

The first commit is rather unrelated to the main goal --- just fixing something left over from switch to 64-bit mode:
  r9301. idStr now takes 32 bytes on 64-bit platforms too.

Here is the actual renaming:
  r9302. Renamed idStr::Empty and idStr::Clear.
So now clearing a string is "Clear" instead of "Empty".
And clearing with dynamic buffer release is called "ClearFree" instead of "Clear".
stgatilov

stgatilov

23.04.2021 03:19

administrator   ~0013898

And two more commits:
  r9303. Revised Clear methods in more idlib classes.
  r9304. Reviewed idWinding Clear methods.

Now all frequently usable containers from idlib follow the same policy:
  ClearFree() makes container empty and frees all dynamic memory
  Clear() makes container empty and retains as much memory buffers as possible
Some classes have only one of these methods (whichever makes sense).
stgatilov

stgatilov

23.04.2021 05:29

administrator   ~0013899

Added idList::Reserve in svn rev 9306.

Issue History

Date Modified Username Field Change
20.04.2021 13:56 stgatilov New Issue
20.04.2021 13:56 stgatilov Status new => assigned
20.04.2021 13:56 stgatilov Assigned To => stgatilov
21.04.2021 15:14 stgatilov Note Added: 0013890
21.04.2021 15:26 stgatilov Note Added: 0013891
21.04.2021 16:56 stgatilov Note Added: 0013892
22.04.2021 02:22 nbohr1more Note Added: 0013893
22.04.2021 03:14 stgatilov Note Added: 0013894
22.04.2021 04:56 nbohr1more Note Added: 0013895
22.04.2021 14:50 stgatilov Note Added: 0013896
22.04.2021 15:22 stgatilov Note Edited: 0013896
22.04.2021 17:36 stgatilov Note Added: 0013897
23.04.2021 03:19 stgatilov Note Added: 0013898
23.04.2021 03:19 stgatilov Status assigned => resolved
23.04.2021 03:19 stgatilov Resolution open => fixed
23.04.2021 03:19 stgatilov Fixed in Version => TDM 2.10
23.04.2021 05:29 stgatilov Note Added: 0013899