Skip to content

Commit

Permalink
wip shield plugin from ext2 and mods
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Nov 30, 2024
1 parent 2cad5e9 commit 644ad2f
Show file tree
Hide file tree
Showing 6 changed files with 782 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/shared/core/memory_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace core::memory_allocator {
}

template<typename T = void>
T* Alloc(size_t len) {
totalLen += len;
void* ptr = new byte[len];
T* Alloc(size_t size = sizeof(T), size_t count = 1) {
totalLen += size * count;
void* ptr = new byte[size * count];
ptrs.push_back(ptr);
return (T*)ptr;
}
Expand All @@ -35,6 +35,21 @@ namespace core::memory_allocator {
std::memcpy(ptr, str, len + 1);
return ptr;
}

void Free(void* ptr) {
if (!ptr) return;

auto it = ptrs.begin();
while (it != ptrs.end()) {
if (*it == ptr) {
delete[] ptr;
it = ptrs.erase(it);
}
else {
it++;
}
}
}
};

}
Loading

0 comments on commit 644ad2f

Please sign in to comment.