aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ringbuffer.h11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/ringbuffer.h b/src/ringbuffer.h
index 9480043..625f65b 100644
--- a/src/ringbuffer.h
+++ b/src/ringbuffer.h
@@ -16,15 +16,11 @@ namespace Bu
16 nEnd( -2 ) 16 nEnd( -2 )
17 { 17 {
18 aData = va.allocate( nCapacity ); 18 aData = va.allocate( nCapacity );
19 for( int j = 0; j < nCapacity; j++ )
20 {
21 va.construct( &aData[j], value() );
22 }
23 } 19 }
24 20
25 virtual ~RingBuffer() 21 virtual ~RingBuffer()
26 { 22 {
27 for( int j = 0; j < nCapacity; j++ ) 23 for( int j = nStart; j < nEnd; j=(j+1%nCapacity) )
28 { 24 {
29 va.destroy( &aData[j] ); 25 va.destroy( &aData[j] );
30 } 26 }
@@ -52,7 +48,7 @@ namespace Bu
52 { 48 {
53 nStart = 0; 49 nStart = 0;
54 nEnd = 1; 50 nEnd = 1;
55 aData[0] = v; 51 va.construct( &aData[0], v );
56 } 52 }
57 else if( nStart == nEnd ) 53 else if( nStart == nEnd )
58 { 54 {
@@ -60,7 +56,7 @@ namespace Bu
60 } 56 }
61 else 57 else
62 { 58 {
63 aData[nEnd] = v; 59 va.construct( &aData[nEnd], v );
64 nEnd = (nEnd+1)%nCapacity; 60 nEnd = (nEnd+1)%nCapacity;
65 } 61 }
66 } 62 }
@@ -74,6 +70,7 @@ namespace Bu
74 else 70 else
75 { 71 {
76 value &v = aData[nStart]; 72 value &v = aData[nStart];
73 va.destroy( &aData[nStart] );
77 nStart = (nStart+1)%nCapacity; 74 nStart = (nStart+1)%nCapacity;
78 if( nStart == nEnd ) 75 if( nStart == nEnd )
79 { 76 {