diff options
author | David Robillard <d@drobilla.net> | 2010-02-28 18:35:58 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-02-28 18:35:58 +0000 |
commit | 082f526e2523538fe19cd9597b25317af9d0a195 (patch) | |
tree | 8f5b58c6e0ba3fa2df2a659468514a6d317744db /raul | |
parent | 556f42229b596791b8eff00e8e0e668057845585 (diff) | |
download | raul-082f526e2523538fe19cd9597b25317af9d0a195.tar.gz raul-082f526e2523538fe19cd9597b25317af9d0a195.tar.bz2 raul-082f526e2523538fe19cd9597b25317af9d0a195.zip |
Use appropriate allocation for RingBuffer and SRSWQueue (was backwards).
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2508 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul')
-rw-r--r-- | raul/RingBuffer.hpp | 10 | ||||
-rw-r--r-- | raul/SRSWQueue.hpp | 11 |
2 files changed, 12 insertions, 9 deletions
diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp index 23d4d90..77d4256 100644 --- a/raul/RingBuffer.hpp +++ b/raul/RingBuffer.hpp @@ -20,6 +20,7 @@ #include <cassert> #include <cstring> +#include <cstdlib> #include <iostream> #include <glib.h> #include "raul/log.hpp" @@ -34,12 +35,11 @@ namespace Raul { template <typename T> class RingBuffer { public: - /** @param size Size in bytes. */ RingBuffer(size_t size) : _size(size) - , _buf(new T[size]) + , _buf(static_cast<char*>(malloc(size))) { reset(); assert(read_space() == 0); @@ -47,7 +47,7 @@ public: } virtual ~RingBuffer() { - delete[] _buf; + free(_buf); } /** Reset(empty) the ringbuffer. @@ -99,7 +99,7 @@ protected: mutable int _read_ptr; size_t _size; ///< Size (capacity) in bytes - T* _buf; ///< size, event, size, event... + char* _buf; ///< Contents }; @@ -190,7 +190,7 @@ bool RingBuffer<T>::skip(size_t size) { if (read_space() < size) { - warn << "Attempt to skip past end of MIDI ring buffer" << std::endl; + warn << "Attempt to skip past end of RingBuffer" << std::endl; return false; } diff --git a/raul/SRSWQueue.hpp b/raul/SRSWQueue.hpp index c40738a..ae62d66 100644 --- a/raul/SRSWQueue.hpp +++ b/raul/SRSWQueue.hpp @@ -19,7 +19,6 @@ #define RAUL_SRSW_QUEUE_HPP #include <cassert> -#include <cstdlib> #include <boost/utility.hpp> #include "raul/AtomicInt.hpp" @@ -28,6 +27,9 @@ namespace Raul { /** Realtime-safe single-reader single-writer queue (aka lock-free ringbuffer) * + * This is appropriate for a cross-thread queue of fixed size object. If you + * need to do variable sized reads and writes, use Raul::RingBuffer instead. + * * Implemented as a dequeue in a fixed array. This is read/write thread-safe, * pushing and popping may occur simultaneously by seperate threads, but * the push and pop operations themselves are not thread-safe (ie. there can @@ -39,6 +41,7 @@ template <typename T> class SRSWQueue : boost::noncopyable { public: + /** @param size Size in number of elements */ SRSWQueue(size_t size); ~SRSWQueue(); @@ -71,8 +74,8 @@ template<typename T> SRSWQueue<T>::SRSWQueue(size_t size) : _front(0) , _back(0) - , _size(size+1) - , _objects(static_cast<T*>(calloc(_size, sizeof(T)))) + , _size(size + 1) + , _objects(new T[_size]) { assert(size > 1); } @@ -81,7 +84,7 @@ SRSWQueue<T>::SRSWQueue(size_t size) template <typename T> SRSWQueue<T>::~SRSWQueue() { - free(_objects); + delete[] _objects; } |