code reduction
This commit is contained in:
parent
8106dc4683
commit
6201f8006e
2 changed files with 3 additions and 14 deletions
14
memory.cpp
14
memory.cpp
|
@ -16,30 +16,22 @@ memory::memory(const uint32_t size): size(size)
|
||||||
|
|
||||||
if (size > 12 * 8192 && psramFound()) {
|
if (size > 12 * 8192 && psramFound()) {
|
||||||
Serial.println(F("Using PSRAM"));
|
Serial.println(F("Using PSRAM"));
|
||||||
is_psram = true;
|
|
||||||
|
|
||||||
m = reinterpret_cast<uint8_t *>(ps_malloc(size));
|
m = reinterpret_cast<uint8_t *>(ps_malloc(size));
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m = new uint8_t[size]();
|
m = reinterpret_cast<uint8_t *>(calloc(1, size));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
m = new uint8_t[size]();
|
m = reinterpret_cast<uint8_t *>(calloc(1, size));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
memory::~memory()
|
memory::~memory()
|
||||||
{
|
{
|
||||||
#if defined(ESP32)
|
free(m);
|
||||||
if (is_psram)
|
|
||||||
free(m);
|
|
||||||
else
|
|
||||||
delete [] m;
|
|
||||||
#else
|
|
||||||
delete [] m;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory::reset()
|
void memory::reset()
|
||||||
|
|
3
memory.h
3
memory.h
|
@ -13,9 +13,6 @@ class memory
|
||||||
private:
|
private:
|
||||||
const uint32_t size { 0 };
|
const uint32_t size { 0 };
|
||||||
uint8_t *m { nullptr };
|
uint8_t *m { nullptr };
|
||||||
#ifdef ESP32
|
|
||||||
bool is_psram { false };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
memory(const uint32_t size);
|
memory(const uint32_t size);
|
||||||
|
|
Loading…
Add table
Reference in a new issue