mirror of
https://github.com/jakcron/nstool.git
synced 2024-12-22 18:55:29 +00:00
57 lines
814 B
C++
57 lines
814 B
C++
#include "memory_blob.h"
|
|
|
|
using namespace fnd;
|
|
|
|
MemoryBlob::MemoryBlob() :
|
|
mData(),
|
|
mSize(0),
|
|
mVisableSize(0)
|
|
{
|
|
|
|
}
|
|
|
|
fnd::MemoryBlob::MemoryBlob(const byte_t * bytes, size_t len) :
|
|
mData(),
|
|
mSize(0),
|
|
mVisableSize(0)
|
|
{
|
|
alloc(len);
|
|
memcpy(getBytes(), bytes, getSize());
|
|
}
|
|
|
|
void MemoryBlob::alloc(size_t size)
|
|
{
|
|
if (size > mSize)
|
|
{
|
|
allocateMemory(size);
|
|
}
|
|
else
|
|
{
|
|
mVisableSize = size;
|
|
clearMemory();
|
|
}
|
|
}
|
|
|
|
void MemoryBlob::extend(size_t new_size)
|
|
{
|
|
try {
|
|
mData.resize(new_size);
|
|
}
|
|
catch (...) {
|
|
throw fnd::Exception(kModuleName, "extend() failed to allocate memory");
|
|
}
|
|
}
|
|
|
|
void MemoryBlob::allocateMemory(size_t size)
|
|
{
|
|
mSize = (size_t)align(size, kAllocBlockSize);
|
|
mVisableSize = size;
|
|
extend(mSize);
|
|
clearMemory();
|
|
}
|
|
|
|
void MemoryBlob::clearMemory()
|
|
{
|
|
memset(mData.data(), 0, mSize);
|
|
}
|