diff --git a/docs/software/TODO.md b/docs/software/TODO.md index a2ad8e82f..bbec4546c 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -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) diff --git a/src/mesh/MemoryPool.h b/src/mesh/MemoryPool.h index 7f051af13..8c6986e16 100644 --- a/src/mesh/MemoryPool.h +++ b/src/mesh/MemoryPool.h @@ -26,7 +26,6 @@ template 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 Allocator virtual T *alloc(TickType_t maxWait) = 0; }; +/** + * An allocator that just uses regular free/malloc + */ +template class MemoryDynamic : public Allocator +{ + 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 * diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index f9b196d60..914e50d09 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -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 staticPool(MAX_PACKETS); +static MemoryDynamic staticPool; -static MemoryPool staticPool(MAX_PACKETS); Allocator &packetPool = staticPool; /**