CArrayRing256 Simplified class for ring buffer - MetaTrader 5 Library - MT4/MT5 Resources
The CArrayRing256 class is a simplified version of the CArrayRing ring buffer class, but is faster and allows organizing mini time series, indicator mini buffers, short size buffers to store intermediate streaming data within an Expert Advisor or indicator.
Simplified based on properties of uchar-variable, used as array index. For example, in the code
Double large batch [ UCHAR_MAX + 1 ]; // Ring buffer data Uchar index = 0 ; // Buffer element index Although (! stop ()) { array[++index]; // Go to the next element of the buffer ... }
Array indexes always take values between 0 and 255 and never exceed the range of the array dimensions. By simplifying the method itself and improving performance, it allows to remove all checks from the method related to possible exits of indexes other than array exits. But the buffer size will always remain the same and will be 256 elements in size. For many tasks, this is an acceptable alternative to the general purpose CArrayRing class in exchange for increased productivity.
ClassCArrayRing256title
#includeThe CArrayRing256.mqh class file should be placed in the IncOnRingBuffer folder that needs to be created in MQL5\Include\.
class method
//--- Buffer initialization method: blank initialization( Double volume = empty_VALUE // The value of the empty position buffer );
//--- Method to add new elements to the buffer: blank add ( constant double element // add element value );
//--- This method overwrites the element value using the set index: blank Update ( // returns false if an error occurs, returns true if successful constant double element, // new value of element constant uchal index = 0 // element index );
//--- This method returns the value of the element with the set index: Double in ( // Returns the value constant Uchar of the element Index // element index ) constant ;
//--- Method returns the last value written to the buffer element: double final() constant ;
//--- Method overwrites the last element value in the buffer: Blank last ( constant double element // new value of element );
//--- Method returns ring buffer size: integer size();
notes:
The usage of this class is similar to CArrayRing . There are several differences:
Attachment download
📎 carrayring256.mqh (2.85 KB)
Source: MQL5 #1379
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •