Skip to content

Commit

Permalink
Foundation Classes - Add resetSize method and enhance
Browse files Browse the repository at this point in the history
Destroy method in NCollection_Map for better memory management
  • Loading branch information
dpasukhi committed Dec 26, 2024
1 parent dc6f4e3 commit c056946
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/NCollection/NCollection_BaseMap.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ public:
NCollection_ListNode ** myData1;
NCollection_ListNode ** myData2;

void resetSize() { mySize = 0; }

private:
// ---------- PRIVATE FIELDS ------------
Standard_Integer myNbBuckets;
Expand Down
25 changes: 24 additions & 1 deletion src/NCollection/NCollection_Map.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public:
//! Clear data. If doReleaseMemory is false then the table of
//! buckets is not released and will be reused.
void Clear(const Standard_Boolean doReleaseMemory = Standard_False)
{ Destroy (MapNode::delNode, doReleaseMemory); myFirst = myLast = nullptr; }
{ Destroy (MapNode::delNode, doReleaseMemory); }

//! Clear data and reset allocator
void Clear (const Handle(NCollection_BaseAllocator)& theAllocator)
Expand All @@ -388,6 +388,29 @@ public:
NCollection_BaseAllocator::CommonBaseAllocator() );
}

//! Deallocate all node elements
void Destroy(NCollection_DelMapNode fDel, Standard_Boolean doReleaseMemory)
{
if (!IsEmpty())
{
MapNode* aNode = myFirst;
while (aNode)
{
MapNode* aCurNode = aNode;
aNode = aNode->NextSeq();
fDel (aCurNode, myAllocator);
}
myFirst = myLast = nullptr;
memset(myData1, 0, (NbBuckets() + 1) * sizeof(NCollection_ListNode*));
resetSize();
}
if (doReleaseMemory)
{
Standard::Free(myData1);
myData1 = myData2 = nullptr;
}
}

//! Destructor
virtual ~NCollection_Map (void)
{ Clear(true); }
Expand Down

0 comments on commit c056946

Please sign in to comment.