persistentstorage/sql/OsLayer/FileBuf64.h
branchRCL_3
changeset 8 fa9941cf3867
parent 0 08ec8eefde2f
child 15 fcc16690f446
equal deleted inserted replaced
6:5ffdb8f2067f 8:fa9941cf3867
    16 #define FILEBUF64_H
    16 #define FILEBUF64_H
    17 
    17 
    18 #include <f32file.h>
    18 #include <f32file.h>
    19 #include <f32file64.h>
    19 #include <f32file64.h>
    20 
    20 
    21 //Forward declaration
       
    22 struct MFileInitializer64;
       
    23 
       
    24 /**
    21 /**
    25 The RFileBuf64 class provides buffered file read/write operations on a single RFile64 object.
    22 The RFileBuf64 class provides buffered file read/write operations on a single RFile64 object.
    26 RFileBuf64::Read() and RFileBuf64::Write() methods may boost the performance of the read/write file operations up to 30% 
    23 RFileBuf64::Read() and RFileBuf64::Write() methods may boost the performance of the read/write file operations up to 30% 
    27 if compared to their RFile64 equivalents. Especially this is true in the case of a set of sequential read or write
    24 if compared to their RFile64 equivalents. Especially this is true in the case of a set of sequential read or write
    28 operations when the file offset of operation N+1 is the end file offset of operation N plus one byte.
    25 operations when the file offset of operation N+1 is the end file offset of operation N plus one byte.
    45 	  methods: RFileBuf64::Create(), RFileBuf64::Open(), RFileBuf64::Temp() or RFileBuf64::AdoptFromClient().
    42 	  methods: RFileBuf64::Create(), RFileBuf64::Open(), RFileBuf64::Temp() or RFileBuf64::AdoptFromClient().
    46 	  
    43 	  
    47 	  In details, to create a file and access it through a RFileBuf64 object:
    44 	  In details, to create a file and access it through a RFileBuf64 object:
    48 	  
    45 	  
    49 	  	RFs fs;
    46 	  	RFs fs;
    50 	  	//initialize the file session
    47         TInt err = fs.Connect();
    51 	  	...
    48         //check the error
    52 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
    49 	  	...
    53 	  	TInt err = fbuf.Create(fs, <file name>, <file mode>);
    50 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
       
    51 	  	err = fbuf.Create(fs, <file name>, <file mode>);
    54 	  	//check the error
    52 	  	//check the error
    55 	  	
    53 	  	
    56 	  To open an existing file and access it through a RFileBuf64 object:
    54 	  To open an existing file and access it through a RFileBuf64 object:
    57 
    55 
    58 	  	RFs fs;
    56 	  	RFs fs;
    59 	  	//initialize the file session
    57         TInt err = fs.Connect();
    60 	  	...
    58         //check the error
    61 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
    59 	  	...
    62 	  	TInt err = fbuf.Open(fs, <file name>, <file mode>);
    60 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
       
    61 	  	err = fbuf.Open(fs, <file name>, <file mode>);
    63 	  	//check the error
    62 	  	//check the error
    64 	  
    63 	  
    65 	  To create a temporary file and access it through a RFileBuf64 object:
    64 	  To create a temporary file and access it through a RFileBuf64 object:
    66 
    65 
    67 	  	RFs fs;
    66 	  	RFs fs;
    68 	  	//initialize the file session
    67         TInt err = fs.Connect();
    69 	  	...
    68         //check the error
    70 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
    69 	  	...
    71 	  	TInt err = fbuf.Temp(fs, <path>, <file name>, <file mode>);
    70 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
       
    71 	  	err = fbuf.Temp(fs, <path>, <file name>, <file mode>);
    72 	  	//check the error
    72 	  	//check the error
    73 	  
    73 	  
    74 	  To open a file from handle and access it through a RFileBuf64 object:
    74 	  To open a file from handle and access it through a RFileBuf64 object:
    75 
    75 
    76 	  	RFs fs;
    76 	  	RFs fs;
    77 	  	//initialize the file session
    77         TInt err = fs.Connect();
    78 	  	...
    78         //check the error
    79 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
    79 	  	...
    80 	  	TInt err = fbuf.AdoptFromClient(<msg>, <fs handle index>, <file handle index>);
    80 	  	RFileBuf64 fbuf(<N>);									//<N> is the buffer capacity in bytes
       
    81 	  	err = fbuf.AdoptFromClient(<msg>, <fs handle index>, <file handle index>);
    81 	  	//check the error
    82 	  	//check the error
    82 
    83 
    83 	- if the RFileBuf64 object is initialised successfully, now the public RFileBuf64 methods can be called to perform
    84 	- if the RFileBuf64 object is initialised successfully, now the public RFileBuf64 methods can be called to perform
    84 	  requested operations on the file:
    85 	  requested operations on the file:
    85 	  
    86 	  
    97 		fbuf.Close();
    98 		fbuf.Close();
    98 	  
    99 	  
    99 @endcode
   100 @endcode
   100 
   101 
   101 Implementation notes: the current RFileBuf64 implementation is optimised for use by the SQLite OS porting layer.
   102 Implementation notes: the current RFileBuf64 implementation is optimised for use by the SQLite OS porting layer.
   102 	After a detailed investigation of the performed by SQLite file read/write operations it was found that buffering of
   103 	After investigation of SQLite file read/write operations it was found that buffering of
   103 	two or more logical file writes into a single physical file write has a positive impact (as expected) on the performance 
   104 	two or more logical file writes into a single physical file write has a positive impact (as expected) on the performance 
   104 	of the database write operations. But the picture is quite different for the file read operations. The database data is
   105 	of the database write operations. But the picture is quite different for the file read operations. The database data is
   105 	organised in pages with fixed size. After a database is created and set of insert/update/delete operations is performed 
   106 	organised in pages with fixed size. After a database is created and set of insert/update/delete operations is performed 
   106 	on it, after a while the database pages (identified by their numbers) are not sequential in the database file and using
   107 	on it, after a while the database pages (identified by their numbers) are not sequential in the database file and using
   107 	a read-ahead buffer with fixed size makes no sense because for each "page read" request of N bytes, the RFileBuf64 object
   108 	a read-ahead buffer with fixed size makes no sense because for each "page read" request of N bytes, the RFileBuf64 object
   158 
   159 
   159 	TInt Drive(TInt& aDriveNumber, TDriveInfo& aDriveInfo) const;
   160 	TInt Drive(TInt& aDriveNumber, TDriveInfo& aDriveInfo) const;
   160 
   161 
   161 private:
   162 private:
   162 	void Invariant() const;
   163 	void Invariant() const;
   163 	TInt DoInit(MFileInitializer64& aFileInitializer);
   164 	TInt DoPreInit();
       
   165 	TInt DoPostInit(TInt aInitErr);
   164 	void DoDiscard();
   166 	void DoDiscard();
   165 	TInt DoFileSize();
   167 	TInt DoFileSize();
   166 	TInt DoSetFileSize(TInt64 aFileSize);
   168 	TInt DoSetFileSize(TInt64 aFileSize);
   167 	TInt DoFileFlush();
   169 	TInt DoFileFlush();
   168 	TInt DoFileWrite();
   170 	TInt DoFileWrite();