Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -352,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
Expand Down Expand Up @@ -392,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
Expand Down Expand Up @@ -597,16 +595,9 @@ 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++)
for (unsigned thrId = 0; thrId < memory.NumThreads(); thrId++)
memory.ReturnThread(thrId);
}

Expand Down
41 changes: 10 additions & 31 deletions src/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,12 @@

Memory::Memory()
{
Memory::Reset();
}


Memory::~Memory()
{
}


void Memory::Reset()
{
nThreads = 0;
}


void Memory::ResetThread(const unsigned thrId)
{
memory[thrId]->transTable->ResetMemory(TT_RESET_FREE_MEMORY);
memory[thrId]->memUsed = Memory::MemoryInUseMB(thrId);
Memory::Resize(0, DDS_TT_SMALL, 0, 0);
}


Expand All @@ -48,15 +35,14 @@ 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;
delete memory[i];
}
Expand All @@ -66,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)
Expand All @@ -88,22 +75,20 @@ void Memory::Resize(
memory[i]->transTable->MakeTT();
}
}

nThreads = n;
}


int Memory::NumThreads() const
unsigned Memory::NumThreads() const
{
return static_cast<int>(nThreads);
return static_cast<unsigned>(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];
Expand All @@ -117,12 +102,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];
Expand Down
9 changes: 1 addition & 8 deletions src/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class Memory
private:

vector<ThreadData *> memory;
unsigned nThreads;

vector<string> threadSizes;

Expand All @@ -127,10 +126,6 @@ class Memory

~Memory();

void Reset();

void ResetThread(const unsigned thrId);

void ReturnThread(const unsigned thrId);

void Resize(
Expand All @@ -139,14 +134,12 @@ class Memory
const int memDefault_MB,
const int memMaximum_MB);

int NumThreads() const;
unsigned NumThreads() const;

ThreadData * GetPtr(const unsigned thrId);

double MemoryInUseMB(const unsigned thrId) const;

void ReturnAllMemory();

string ThreadSize(const unsigned thrId) const;
};

Expand Down
6 changes: 0 additions & 6 deletions src/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,6 @@ bool System::IsIMPL() const
}


unsigned System::NumThreads() const
{
return static_cast<unsigned>(numThreads);
}


bool System::ThreadOK(const int thrId) const
{
return (thrId >= 0 && thrId < numThreads);
Expand Down
2 changes: 0 additions & 2 deletions src/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class System

bool IsIMPL() const;

unsigned NumThreads() const;

bool ThreadOK(const int thrId) const;

void GetHardware(
Expand Down
1 change: 0 additions & 1 deletion src/dds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static void __attribute__ ((constructor)) libInit(void)
static void __attribute__ ((destructor)) libEnd(void)
{
CloseDebugFiles();
FreeMemory();
}

#endif
Expand Down