Fix #149: Use a simple heap allocator for now, after 1.0 we can go to

fixed sized pools to protect against fragmentation.
1.2-legacy
geeksville 2020-06-12 12:11:18 -07:00
rodzic 88b91de197
commit f0b8f10665
3 zmienionych plików z 22 dodań i 2 usunięć

Wyświetl plik

@ -24,6 +24,7 @@ During the beta timeframe the following improvements 'would be nice'
Items after the first final candidate release.
- Change back to using a fixed sized MemoryPool rather than MemoryDynamic (see bug #149)
- scan to find channels with low background noise? (Use CAD mode of the RF95 to automatically find low noise channels)
- If the phone doesn't read fromradio mailbox within X seconds, assume the phone is gone and we can stop queing location msgs
for it (because it will redownload the nodedb when it comes back)

Wyświetl plik

@ -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
*

Wyświetl plik

@ -23,8 +23,9 @@
(MAX_RX_TOPHONE + MAX_RX_FROMRADIO + MAX_TX_QUEUE + \
2) // max number of packets which can be in flight (either queued from reception or queued for sending)
// static MemoryPool<MeshPacket> staticPool(MAX_PACKETS);
static MemoryDynamic<MeshPacket> staticPool;
static MemoryPool<MeshPacket> staticPool(MAX_PACKETS);
Allocator<MeshPacket> &packetPool = staticPool;
/**