From d128f82023d9110b7f691445471e60415c615544 Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:14:33 +1100 Subject: [PATCH 1/8] Remove FreeThreadMem --- src/Init.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Init.cpp b/src/Init.cpp index 5c2fff0c..73ffa5de 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -28,8 +28,6 @@ void InitConstants(); void InitDebugFiles(); -void FreeThreadMem(); - int lho[DDS_HANDS] = { 1, 2, 3, 0 }; int rho[DDS_HANDS] = { 3, 0, 1, 2 }; @@ -597,13 +595,6 @@ void STDCALL GetDDSInfo(DDSInfo * info) } -void FreeThreadMem() -{ - for (unsigned thrId = 0; thrId < sysdep.NumThreads(); thrId++) - memory.ResetThread(thrId); -} - - void STDCALL FreeMemory() { for (unsigned thrId = 0; thrId < sysdep.NumThreads(); thrId++) From 9ba6293f7c135e9538bd9d39e2461633b494011a Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:17:24 +1100 Subject: [PATCH 2/8] Remove Memory::ReturnAllMemory --- src/Memory.cpp | 6 ------ src/Memory.h | 2 -- 2 files changed, 8 deletions(-) diff --git a/src/Memory.cpp b/src/Memory.cpp index f333d01f..82d322a0 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -117,12 +117,6 @@ double Memory::MemoryInUseMB(const unsigned thrId) const } -void Memory::ReturnAllMemory() -{ - Memory::Resize(0, DDS_TT_SMALL, 0, 0); -} - - string Memory::ThreadSize(const unsigned thrId) const { return threadSizes[thrId]; diff --git a/src/Memory.h b/src/Memory.h index 3f86fa35..4b15a7d6 100644 --- a/src/Memory.h +++ b/src/Memory.h @@ -145,8 +145,6 @@ class Memory double MemoryInUseMB(const unsigned thrId) const; - void ReturnAllMemory(); - string ThreadSize(const unsigned thrId) const; }; From bbf04411ee3d923eb4574a2bd39ea251a1352786 Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:23:28 +1100 Subject: [PATCH 3/8] Remove Memory::ResetThread --- src/Memory.cpp | 7 ------- src/Memory.h | 2 -- 2 files changed, 9 deletions(-) diff --git a/src/Memory.cpp b/src/Memory.cpp index 82d322a0..72952db1 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -28,13 +28,6 @@ void Memory::Reset() } -void Memory::ResetThread(const unsigned thrId) -{ - memory[thrId]->transTable->ResetMemory(TT_RESET_FREE_MEMORY); - memory[thrId]->memUsed = Memory::MemoryInUseMB(thrId); -} - - void Memory::ReturnThread(const unsigned thrId) { memory[thrId]->transTable->ReturnAllMemory(); diff --git a/src/Memory.h b/src/Memory.h index 4b15a7d6..8d05e3c1 100644 --- a/src/Memory.h +++ b/src/Memory.h @@ -129,8 +129,6 @@ class Memory void Reset(); - void ResetThread(const unsigned thrId); - void ReturnThread(const unsigned thrId); void Resize( From 311d495189c25320feeb39bbf87bbdeb27c85b31 Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:25:11 +1100 Subject: [PATCH 4/8] Remove Memory::nThreads in favour of vector size() --- src/Memory.cpp | 26 +++++++++----------------- src/Memory.h | 5 +---- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/Memory.cpp b/src/Memory.cpp index 72952db1..7402c99d 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -13,7 +13,6 @@ Memory::Memory() { - Memory::Reset(); } @@ -22,12 +21,6 @@ Memory::~Memory() } -void Memory::Reset() -{ - nThreads = 0; -} - - void Memory::ReturnThread(const unsigned thrId) { memory[thrId]->transTable->ReturnAllMemory(); @@ -41,13 +34,13 @@ void Memory::Resize( const int memDefault_MB, const int memMaximum_MB) { - if (nThreads == n) + if (memory.size() == n) return; - if (nThreads > n) + if (memory.size() > n) { // Downsize. - for (unsigned i = n; i < nThreads; i++) + for (unsigned i = n; i < memory.size(); i++) { memory[i]->transTable->ReturnAllMemory(); delete memory[i]->transTable; @@ -59,9 +52,10 @@ void Memory::Resize( else { // Upsize. + unsigned oldSize = memory.size(); memory.resize(n); threadSizes.resize(n); - for (unsigned i = nThreads; i < n; i++) + for (unsigned i = oldSize; i < n; i++) { memory[i] = new ThreadData; if (flag == DDS_TT_SMALL) @@ -81,22 +75,20 @@ void Memory::Resize( memory[i]->transTable->MakeTT(); } } - - nThreads = n; } -int Memory::NumThreads() const +unsigned Memory::NumThreads() const { - return static_cast(nThreads); + return static_cast(memory.size()); } ThreadData * Memory::GetPtr(const unsigned thrId) { - if (thrId >= nThreads) + if (thrId >= memory.size()) { - cout << "Memory::GetPtr: " << thrId << " vs. " << nThreads << endl; + cout << "Memory::GetPtr: " << thrId << " vs. " << memory.size() << endl; exit(1); } return memory[thrId]; diff --git a/src/Memory.h b/src/Memory.h index 8d05e3c1..90b928dc 100644 --- a/src/Memory.h +++ b/src/Memory.h @@ -117,7 +117,6 @@ class Memory private: vector memory; - unsigned nThreads; vector threadSizes; @@ -127,8 +126,6 @@ class Memory ~Memory(); - void Reset(); - void ReturnThread(const unsigned thrId); void Resize( @@ -137,7 +134,7 @@ class Memory const int memDefault_MB, const int memMaximum_MB); - int NumThreads() const; + unsigned NumThreads() const; ThreadData * GetPtr(const unsigned thrId); From e152bce9a717500ecb8005299a84c5e98c66fbf4 Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:26:43 +1100 Subject: [PATCH 5/8] Remove redundant call to TransTable::ReturnAllMemory Already called in ~TransTable() --- src/Memory.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Memory.cpp b/src/Memory.cpp index 7402c99d..aca50a1c 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -42,7 +42,6 @@ void Memory::Resize( // Downsize. for (unsigned i = n; i < memory.size(); i++) { - memory[i]->transTable->ReturnAllMemory(); delete memory[i]->transTable; delete memory[i]; } From 65efd6a59bf6015c1d0d1b94f7d1b3a057c44431 Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:28:19 +1100 Subject: [PATCH 6/8] Use Memory::NumThreads when iterating memory to avoid OOB --- src/Init.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Init.cpp b/src/Init.cpp index 73ffa5de..cad96d3c 100644 --- a/src/Init.cpp +++ b/src/Init.cpp @@ -350,7 +350,7 @@ void InitConstants() void InitDebugFiles() { - for (unsigned thrId = 0; thrId < sysdep.NumThreads(); thrId++) + for (unsigned thrId = 0; thrId < memory.NumThreads(); thrId++) { ThreadData * thrp = memory.GetPtr(thrId); UNUSED(thrp); // To avoid compile errors @@ -390,7 +390,7 @@ void InitDebugFiles() void CloseDebugFiles() { - for (unsigned thrId = 0; thrId < sysdep.NumThreads(); thrId++) + for (unsigned thrId = 0; thrId < memory.NumThreads(); thrId++) { ThreadData * thrp = memory.GetPtr(thrId); UNUSED(thrp); // To avoid compiler warning @@ -597,7 +597,7 @@ void STDCALL GetDDSInfo(DDSInfo * info) void STDCALL FreeMemory() { - for (unsigned thrId = 0; thrId < sysdep.NumThreads(); thrId++) + for (unsigned thrId = 0; thrId < memory.NumThreads(); thrId++) memory.ReturnThread(thrId); } From 0b2c209f79dfb6b500fa913470db44ee3ed40ee3 Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:29:29 +1100 Subject: [PATCH 7/8] Remove System::NumThreads --- src/System.cpp | 6 ------ src/System.h | 2 -- 2 files changed, 8 deletions(-) diff --git a/src/System.cpp b/src/System.cpp index 3deb5180..52f727b7 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -274,12 +274,6 @@ bool System::IsIMPL() const } -unsigned System::NumThreads() const -{ - return static_cast(numThreads); -} - - bool System::ThreadOK(const int thrId) const { return (thrId >= 0 && thrId < numThreads); diff --git a/src/System.h b/src/System.h index fd7e8fcc..9f78fea3 100644 --- a/src/System.h +++ b/src/System.h @@ -97,8 +97,6 @@ class System bool IsIMPL() const; - unsigned NumThreads() const; - bool ThreadOK(const int thrId) const; void GetHardware( From 086075dbf012138273c2efccebe0af3dc0448e83 Mon Sep 17 00:00:00 2001 From: Rhys Date: Tue, 7 Jan 2020 16:30:10 +1100 Subject: [PATCH 8/8] Clean up memory in ~Memory() --- src/Memory.cpp | 1 + src/dds.cpp | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Memory.cpp b/src/Memory.cpp index aca50a1c..62e8dcc1 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -18,6 +18,7 @@ Memory::Memory() Memory::~Memory() { + Memory::Resize(0, DDS_TT_SMALL, 0, 0); } diff --git a/src/dds.cpp b/src/dds.cpp index fad30225..f6415ec2 100644 --- a/src/dds.cpp +++ b/src/dds.cpp @@ -73,7 +73,6 @@ static void __attribute__ ((constructor)) libInit(void) static void __attribute__ ((destructor)) libEnd(void) { CloseDebugFiles(); - FreeMemory(); } #endif