Changeset 2508

Show
Ignore:
Timestamp:
02/28/10 10:35:58 (6 months ago)
Author:
drobilla
Message:

Use appropriate allocation for RingBuffer? and SRSWQueue (was backwards).

Location:
trunk/raul/raul
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/raul/raul/RingBuffer.hpp

    r2348 r2508  
    2121#include <cassert> 
    2222#include <cstring> 
     23#include <cstdlib> 
    2324#include <iostream> 
    2425#include <glib.h> 
     
    3536class RingBuffer { 
    3637public: 
    37  
    3838        /** @param size Size in bytes. 
    3939         */ 
    4040        RingBuffer(size_t size) 
    4141                : _size(size) 
    42                 , _buf(new T[size]) 
     42                , _buf(static_cast<char*>(malloc(size))) 
    4343        { 
    4444                reset(); 
     
    4848 
    4949        virtual ~RingBuffer() { 
    50                 delete[] _buf; 
     50                free(_buf); 
    5151        } 
    5252 
     
    100100 
    101101        size_t _size; ///< Size (capacity) in bytes 
    102         T*     _buf;  ///< size, event, size, event... 
     102        char*  _buf;  ///< Contents 
    103103}; 
    104104 
     
    191191{ 
    192192        if (read_space() < size) { 
    193                 warn << "Attempt to skip past end of MIDI ring buffer" << std::endl; 
     193                warn << "Attempt to skip past end of RingBuffer" << std::endl; 
    194194                return false; 
    195195        } 
  • trunk/raul/raul/SRSWQueue.hpp

    r2432 r2508  
    2020 
    2121#include <cassert> 
    22 #include <cstdlib> 
    2322#include <boost/utility.hpp> 
    2423#include "raul/AtomicInt.hpp" 
     
    2827 
    2928/** Realtime-safe single-reader single-writer queue (aka lock-free ringbuffer) 
     29 * 
     30 * This is appropriate for a cross-thread queue of fixed size object.  If you 
     31 * need to do variable sized reads and writes, use Raul::RingBuffer instead. 
    3032 * 
    3133 * Implemented as a dequeue in a fixed array.  This is read/write thread-safe, 
     
    4042{ 
    4143public: 
     44        /** @param size Size in number of elements */ 
    4245        SRSWQueue(size_t size); 
    4346        ~SRSWQueue(); 
     
    7275        : _front(0) 
    7376        , _back(0) 
    74         , _size(size+1) 
    75         , _objects(static_cast<T*>(calloc(_size, sizeof(T)))) 
     77        , _size(size + 1) 
     78        , _objects(new T[_size]) 
    7679{ 
    7780        assert(size > 1); 
     
    8285SRSWQueue<T>::~SRSWQueue() 
    8386{ 
    84         free(_objects); 
     87        delete[] _objects; 
    8588} 
    8689