bolar_2 backup
This commit is contained in:
33
main/core/psram_object.h
Normal file
33
main/core/psram_object.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
|
||||
#include <esp_heap_caps.h>
|
||||
|
||||
namespace borla {
|
||||
|
||||
template <typename T>
|
||||
struct PsramObjectDeleter {
|
||||
void operator()(T* object) const
|
||||
{
|
||||
if (object != nullptr) {
|
||||
object->~T();
|
||||
heap_caps_free(object);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::unique_ptr<T, PsramObjectDeleter<T>> MakePsramObject()
|
||||
{
|
||||
void* memory = heap_caps_malloc(
|
||||
sizeof(T), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (memory == nullptr) {
|
||||
return {};
|
||||
}
|
||||
return std::unique_ptr<T, PsramObjectDeleter<T>>(
|
||||
new (memory) T());
|
||||
}
|
||||
|
||||
} // namespace borla
|
||||
Reference in New Issue
Block a user