mirror of
https://github.com/thunderbrewhq/squall.git
synced 2026-02-04 00:49:08 +00:00
feat(memory): add SMemFill
This commit is contained in:
parent
8e9fb741b6
commit
2efa5339e2
3 changed files with 29 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "storm/Memory.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
constexpr size_t ALIGNMENT = 8;
|
||||
|
||||
void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags) {
|
||||
|
|
@ -21,6 +23,10 @@ void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t
|
|||
}
|
||||
}
|
||||
|
||||
void SMemFill(void* ptr, size_t bytes, uint8_t value) {
|
||||
memset(ptr, value, bytes);
|
||||
}
|
||||
|
||||
void SMemFree(void* ptr) {
|
||||
if (ptr) {
|
||||
free(ptr);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags = 0);
|
||||
|
||||
void SMemFill(void* ptr, size_t bytes, uint8_t value);
|
||||
|
||||
void SMemFree(void* ptr);
|
||||
|
||||
void SMemFree(void* ptr, const char* filename, int32_t linenumber, uint32_t flags = 0);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,27 @@ TEST_CASE("SMemAlloc", "[memory]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SMemFill", "[memory]") {
|
||||
std::vector<uint8_t> data = { 1, 255, 128, 42, 69, 99, 13, 37 };
|
||||
|
||||
SECTION("replaces bytes") {
|
||||
std::vector<uint8_t> result1(8, 255);
|
||||
SMemFill(data.data(), 8, 255);
|
||||
CHECK_THAT(data, Catch::Matchers::Equals(result1));
|
||||
|
||||
std::vector<uint8_t> result2 = { 0, 0, 0, 0, 0, 255, 255, 255 };
|
||||
SMemFill(data.data(), 5, 0);
|
||||
CHECK_THAT(data, Catch::Matchers::Equals(result2));
|
||||
}
|
||||
|
||||
SECTION("does nothing if size is 0") {
|
||||
std::vector<uint8_t> changedata = data;
|
||||
SMemFill(changedata.data(), 0, 255);
|
||||
|
||||
CHECK_THAT(changedata, Catch::Matchers::Equals(data));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SMemFree", "[memory]") {
|
||||
SECTION("does nothing on nullptr") {
|
||||
CHECK_NOTHROW(SMemFree(nullptr));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue