mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-21 18:22:32 +00:00
Fix #149: Use a simple heap allocator for now, after 1.0 we can go to
fixed sized pools to protect against fragmentation.
This commit is contained in:
@@ -26,7 +26,6 @@ template <class T> class Allocator
|
||||
T *allocZeroed(TickType_t maxWait)
|
||||
{
|
||||
T *p = alloc(maxWait);
|
||||
assert(p);
|
||||
|
||||
if (p)
|
||||
memset(p, 0, sizeof(T));
|
||||
@@ -52,6 +51,25 @@ template <class T> class Allocator
|
||||
virtual T *alloc(TickType_t maxWait) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* An allocator that just uses regular free/malloc
|
||||
*/
|
||||
template <class T> class MemoryDynamic : public Allocator<T>
|
||||
{
|
||||
public:
|
||||
/// Return a buffer for use by others
|
||||
virtual void release(T *p)
|
||||
{
|
||||
assert(p);
|
||||
free(p);
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you
|
||||
/// probably don't want this version).
|
||||
virtual T *alloc(TickType_t maxWait) { return (T *)malloc(sizeof(T)); }
|
||||
};
|
||||
|
||||
/**
|
||||
* A pool based allocator
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user