This commit is contained in:
IlushaShurupov 2023-07-16 18:28:24 +03:00 committed by Ilya Shurupov
parent f91b45643d
commit 53aa0e34a8
24 changed files with 116 additions and 110 deletions

View file

@ -80,7 +80,7 @@ namespace tp {
}
explicit Buffer(ualni size) : mSize(size), mLoad(0) {
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * tMinSize);
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * size);
}
Buffer(const Buffer& in) : mSize(in.mSize), mLoad(in.mLoad) {

View file

@ -7,7 +7,10 @@ namespace tp {
template< typename tType, ualni tSizeX, ualni tSizeY >
using ConstSizeBuffer2D = ConstSizeBuffer<ConstSizeBuffer<tType, tSizeX>, tSizeY>;
template <typename tType>
template <
typename tType,
class tAllocator = DefaultAllocator
>
class Buffer2D {
public:
typedef ualni Index;
@ -15,15 +18,28 @@ namespace tp {
typedef SelCopyArg<tType> tTypeArg;
private:
tAllocator mAlloc;
tType* mBuff = nullptr;
Index2D mSize = { 0, 0 };
void deleteBuffer() {
if (!mBuff) return;
for (ualni i = 0; i < mSize.x * mSize.y; i++) mBuff[i].~tType();
mAlloc.deallocate(mBuff);
}
void allocateBuffer(Index2D size) {
deleteBuffer();
mBuff = (tType*) mAlloc.allocate(sizeof(tType) * size.x * size.y);
for (ualni i = 0; i < mSize.x * mSize.y; i++) new (mBuff + i) tType();
}
public:
Buffer2D() = default;
~Buffer2D() {
delete mBuff;
deleteBuffer();
}
explicit Buffer2D(Index2D aSize) {
@ -55,8 +71,7 @@ namespace tp {
void reserve(const Index2D& newSize) {
if (mSize.x != newSize.x || mSize.y != newSize.y) {
delete mBuff;
mBuff = new tType[newSize.x * newSize.y];
allocateBuffer(newSize);
mSize = newSize;
}
}

View file

@ -387,6 +387,13 @@ namespace tp {
}
}
~Map() { removeAll(); }
~Map() {
for (ualni i = 0; i < mNSlots; i++) {
if (mTable[i] && !isDeletedNode(mTable[i])) {
deleteNode(mTable[i]);
}
}
deleteTable(mTable);
}
};
}