2016-03-10 22:36:46 +00:00
|
|
|
#include "InProcessMemory.h"
|
|
|
|
|
|
|
|
#include "LinearMath/btHashMap.h"
|
|
|
|
|
|
|
|
struct InProcessMemoryInternalData
|
|
|
|
{
|
|
|
|
btHashMap<btHashInt, void*> m_memoryPointers;
|
|
|
|
};
|
|
|
|
|
|
|
|
InProcessMemory::InProcessMemory()
|
|
|
|
{
|
|
|
|
m_data = new InProcessMemoryInternalData;
|
|
|
|
}
|
|
|
|
|
|
|
|
InProcessMemory::~InProcessMemory()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_data->m_memoryPointers.size(); i++)
|
2016-03-10 22:36:46 +00:00
|
|
|
{
|
|
|
|
void** ptrptr = m_data->m_memoryPointers.getAtIndex(i);
|
|
|
|
if (ptrptr)
|
|
|
|
{
|
|
|
|
void* ptr = *ptrptr;
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete m_data;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void* InProcessMemory::allocateSharedMemory(int key, int size, bool allowCreation)
|
2016-03-10 22:36:46 +00:00
|
|
|
{
|
|
|
|
void** ptrptr = m_data->m_memoryPointers[key];
|
|
|
|
if (ptrptr)
|
|
|
|
{
|
|
|
|
return *ptrptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* ptr = malloc(size);
|
2018-09-23 21:17:31 +00:00
|
|
|
m_data->m_memoryPointers.insert(key, ptr);
|
2016-03-10 22:36:46 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void InProcessMemory::releaseSharedMemory(int /*key*/, int /*size*/)
|
2016-03-10 22:36:46 +00:00
|
|
|
{
|
|
|
|
//we don't release the memory here, but in the destructor instead,
|
|
|
|
//so multiple users could 'share' the memory given some key
|
|
|
|
}
|