Added fast full buffered I/O buffer in fortran
This commit is contained in:
parent
6c74ca6504
commit
0451d8e650
4 changed files with 66 additions and 3 deletions
|
@ -63,11 +63,14 @@ UnformattedRead::UnformattedRead(const char *fname)
|
|||
swapOrdering = false;
|
||||
cSize = Check_32bits;
|
||||
checkPointRef = checkPointAccum = 0;
|
||||
recordBuffer = 0;
|
||||
}
|
||||
|
||||
|
||||
UnformattedRead::~UnformattedRead()
|
||||
{
|
||||
if (recordBuffer != 0)
|
||||
delete[] recordBuffer;
|
||||
delete f;
|
||||
}
|
||||
|
||||
|
@ -115,7 +118,7 @@ void UnformattedRead::skip(int64_t off)
|
|||
checkPointAccum += off;
|
||||
}
|
||||
|
||||
void UnformattedRead::beginCheckpoint()
|
||||
void UnformattedRead::beginCheckpoint(bool bufferRecord)
|
||||
throw (InvalidUnformattedAccess,EndOfFileException)
|
||||
{
|
||||
if (checkPointAccum != 0)
|
||||
|
@ -129,11 +132,21 @@ void UnformattedRead::beginCheckpoint()
|
|||
|
||||
if (f->eof())
|
||||
throw EndOfFileException();
|
||||
|
||||
if (bufferRecord) {
|
||||
recordBuffer = new uint8_t[checkPointRef];
|
||||
f->read(reinterpret_cast<char *>(recordBuffer), checkPointRef);
|
||||
}
|
||||
}
|
||||
|
||||
void UnformattedRead::endCheckpoint(bool autodrop)
|
||||
throw (InvalidUnformattedAccess)
|
||||
{
|
||||
if (recordBuffer != 0) {
|
||||
delete[] recordBuffer;
|
||||
recordBuffer = 0;
|
||||
}
|
||||
|
||||
if (checkPointRef != checkPointAccum)
|
||||
{
|
||||
if (!autodrop || checkPointAccum > checkPointRef) {
|
||||
|
@ -161,7 +174,11 @@ void UnformattedRead::readOrderedBuffer(void *buffer, int size)
|
|||
if ((checkPointAccum+(uint64_t)size) > checkPointRef)
|
||||
throw InvalidUnformattedAccess();
|
||||
|
||||
f->read((char *)buffer, size);
|
||||
if (recordBuffer != 0) {
|
||||
memcpy(buffer, &recordBuffer[checkPointAccum], size);
|
||||
} else {
|
||||
f->read((char *)buffer, size);
|
||||
}
|
||||
|
||||
if (swapOrdering)
|
||||
{
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace CosmoTool
|
|||
|
||||
uint64_t getBlockSize() const { return checkPointRef; }
|
||||
|
||||
void beginCheckpoint()
|
||||
void beginCheckpoint(bool bufferRecord = false)
|
||||
throw (InvalidUnformattedAccess,EndOfFileException);
|
||||
void endCheckpoint(bool autodrop = false)
|
||||
throw (InvalidUnformattedAccess);
|
||||
|
@ -109,6 +109,7 @@ namespace CosmoTool
|
|||
uint64_t checkPointRef;
|
||||
uint64_t checkPointAccum;
|
||||
std::ifstream *f;
|
||||
uint8_t *recordBuffer;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue