nstool/lib/libfnd/include/fnd/MemoryBlob.h

43 lines
1,021 B
C
Raw Normal View History

2017-07-02 15:18:59 +00:00
#pragma once
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <fnd/types.h>
namespace fnd
{
class MemoryBlob
{
public:
MemoryBlob();
MemoryBlob(const byte_t* bytes, size_t len);
2017-07-02 15:18:59 +00:00
bool operator==(const MemoryBlob& other) const;
bool operator!=(const MemoryBlob& other) const;
void operator=(const MemoryBlob& other);
void alloc(size_t size);
void extend(size_t new_size);
void clear();
2017-07-02 15:18:59 +00:00
inline byte_t& operator[](size_t index) { return mData[index]; }
inline const byte_t& operator[](size_t index) const { return mData[index]; }
2017-07-02 15:18:59 +00:00
inline byte_t* getBytes() { return mData.data(); }
inline const byte_t* getBytes() const { return mData.data(); }
inline size_t getSize() const { return mVisableSize; }
2017-07-02 15:18:59 +00:00
private:
const std::string kModuleName = "MEMORY_BLOB";
static const size_t kAllocBlockSize = 0x1000;
2017-07-02 15:18:59 +00:00
std::vector<byte_t> mData;
size_t mSize;
size_t mVisableSize;
2017-07-02 15:18:59 +00:00
void allocateMemory(size_t size);
void clearMemory();
2017-07-02 15:18:59 +00:00
};
}