Archived issue #0021711
Assignment operator for maps in NCollection unnecessarily increases buckets array
Description
Map data structures in NCollection share common bug: in operator =, the target
map is resized using number of buckets of source map instead of its actual
content (extent). This leads to the fact that when map is copied, the resulting
map has buckets re-allocated to the next threshold value; this leads to
unnecessary allocation of memory.
The test executable demonstrating this behavior is attached. Its output on
current OCCT is:
:KAS:dev:abvdoc> testmap
Testing NCollection_Map
Initial number of buckets: 101
Copy #0000002: number of buckets = 2003
Copy #4: number of buckets = 10007
Copy #6: number of buckets = 37003
Copy #0000008: number of buckets = 65003
Copy #10: number of buckets = 209953
Copy #12: number of buckets = 995329
Copy #0000014: number of buckets = 995329
Copy #0000016: number of buckets = 995329
Copy #0000018: number of buckets = 995329
Copy #0000020: number of buckets = 995329
Testing TCollection_Map
Initial number of buckets: 101
Copy #0000002: number of buckets = 101
Copy #4: number of buckets = 101
Copy #6: number of buckets = 101
Copy #0000008: number of buckets = 101
Copy #10: number of buckets = 101
Copy #12: number of buckets = 101
Copy #0000014: number of buckets = 101
Copy #0000016: number of buckets = 101
Copy #0000018: number of buckets = 101
Copy #0000020: number of buckets = 101
Note that maps in TCollection does not suffer from such problem.
map is resized using number of buckets of source map instead of its actual
content (extent). This leads to the fact that when map is copied, the resulting
map has buckets re-allocated to the next threshold value; this leads to
unnecessary allocation of memory.
The test executable demonstrating this behavior is attached. Its output on
current OCCT is:
:KAS:dev:abvdoc> testmap
Testing NCollection_Map
Initial number of buckets: 101
Copy #0000002: number of buckets = 2003
Copy #4: number of buckets = 10007
Copy #6: number of buckets = 37003
Copy #0000008: number of buckets = 65003
Copy #10: number of buckets = 209953
Copy #12: number of buckets = 995329
Copy #0000014: number of buckets = 995329
Copy #0000016: number of buckets = 995329
Copy #0000018: number of buckets = 995329
Copy #0000020: number of buckets = 995329
Testing TCollection_Map
Initial number of buckets: 101
Copy #0000002: number of buckets = 101
Copy #4: number of buckets = 101
Copy #6: number of buckets = 101
Copy #0000008: number of buckets = 101
Copy #10: number of buckets = 101
Copy #12: number of buckets = 101
Copy #0000014: number of buckets = 101
Copy #0000016: number of buckets = 101
Copy #0000018: number of buckets = 101
Copy #0000020: number of buckets = 101
Note that maps in TCollection does not suffer from such problem.
Additional information
Documentation remark, added by Author 2010-08-03 14:05:28:
Improvements:
The bug in copy function (operator =) of all map data structures in NCollection
has been fixed: the target map was resized using number of buckets of source map
instead of its actual content (extent). This led to unnecessary growth of
allocated memory whenever map was copied.
Improvements:
The bug in copy function (operator =) of all map data structures in NCollection
has been fixed: the target map was resized using number of buckets of source map
instead of its actual content (extent). This led to unnecessary growth of
allocated memory whenever map was copied.
Public activity
No public notes
Participants are labeled by their role within this record.