CFastFile - Class for using uchar arrays as virtual files - MetaTrader 5 library
CFastFile eliminates the need for intermediate writing of data to a physical file on disk. It provides significant speedup when processing data.
Its functionality is similar to the standard FileWriteXXX/FileReadXXX functionality. This means you can easily move from working with physical files to working quickly with "virtual" files in memory. Data storage and reading/writing are based on using Uchar -arrays instead of physical files.
Function list:
CFastFile( urchar &data[]); //Constructor initializing file data from array blank clear(); //Clear file //--- Functions for handling file attributes blank_delim ( urchar_delim = ';' ); // Set delimiter (data delimiter) for CSV mode integer size(); // Get file size integer tell(); // Get current position blank_find ( integer offset, integer origin); // Look for boolean IsEnding(); // Check end-of-file (EOF) boolean IsLineEnding(); // Check end of line //--- Function to write data to file unit write array ( uchar &src[], unit src_start= 0 , integer src_cnt= entire array ); //Write uchar array unit write double ( double five); //Write double precision unit write floating point ( floating five); The unit is written as long ( long five); The unit is written as an integer ( integer five); The unit is written as short ( short five); unit writing character ( character five); Unit write integer ( integer five, integer sz=INT_VALUE); // Write integer - for compatibility with standard FileWriteInteger unit write string ( string five, integer carbon nanotube ); // Write the string cnt=-1 to indicate CSV mode plus \r\n //--- Function unit read array from file ( wchar &dst[], unit target start = 0 , integer cnt = entire array ); // Read array double ReadDouble(); // Read double float ReadFloat(); longReadLength (); IntegerReadInt (); ShortReadShort (); CharacterReadChar (); integer read integer ( integer sz=INT_VALUE); // read integer - compatible with standard FileReadInteger double read(); // string read string ( integer carbon nanotube); read string. cnt=-1 means CSV mode - read to delimiter (data delimiter) //--- Function for saving data unit save( uchar &v[]); // Save the file to uchar array unit save( integer h); // Save the file to a real file on disk. h - file handle (file must be open) unit save( string file); // Save the file to a real file on disk. File - filename // --- function for loading data unit load ( uchar &v[]); // Load file unit load ( integer h) from uchar array ; // Load data from a real file on disk. h - file handle (file must be open) unit load( string file); // Load data from a real file on disk. file - filename
As you can see, the functions are named similar to standard file operations .
Migrating from real files to quick files is easy. Instead of opening the file and getting the file handle (for example, the integer h ) you need to create a CFastFile class instance, for example:
CFastFile f;
Next you need to change the regular file functions according to the rules:
FileWriteDouble ( hour , 10 ) -> f .WriteDouble( 10 )
Added for convenience, Save/Load functionality - which allows you to save/load "virtual" file data to real files on disk.
Contains a demonstration example using the CFastFile class.
Attachment download
📎 fastfile_example.mq5 (1.75 KB)
📎 fastfile.mqh (13.95 KB)
Source: MQL5 #845
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •