[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Tue Oct 16 14:48:09 UTC 2012
SVN commit 1320712 by kuemmel:
array is now managed by a smart pointer
M +5 -13 asciifilebuffer.cpp
M +1 -10 asciifiledata.cpp
M +0 -1 asciifiledata.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.cpp #1320711:1320712
@@ -53,9 +53,6 @@
//-------------------------------------------------------------------------------------------
void AsciiFileBuffer::clear()
{
- foreach (AsciiFileData chunk, _fileData) {
- chunk.release();
- }
_fileData.clear();
_begin = -1;
_bytesRead = 0;
@@ -138,29 +135,24 @@
_bytesRead = bytesToRead;
_fileData << wholeFile;
return;
- } else {
- wholeFile.release();
}
// reading whole file into one array failed, try to read into smaller arrays
int chunkSize = _defaultChunkSize;
_fileData = splitFile(chunkSize, rowIndex, start, bytesToRead);
- _bytesRead = 0;
- foreach (AsciiFileData chunk, _fileData) {
+ for (int i = 0; i < _fileData.size(); i++) {
// use alread set
- chunk.setFile(_file);
- if (!chunk.read()) {
+ _fileData[i].setFile(_file);
+ if (!_fileData[i].read()) {
Kst::Debug::self()->log(QString("AsciiFileBuffer: error when reading into chunk"));
- chunk.release();
break;
}
- _bytesRead += chunk.bytesRead();
+ _bytesRead += _fileData[i].bytesRead();
}
if (_bytesRead == bytesToRead) {
_begin = start;
} else {
- _bytesRead = 0;
- _fileData.clear();
+ clear();
Kst::Debug::self()->log(QString("AsciiFileBuffer: error while reading %1 chunks").arg(_fileData.size()));
}
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifiledata.cpp #1320711:1320712
@@ -145,7 +145,7 @@
try {
_array->resize(bytes);
} catch (const std::bad_alloc&) {
- // work around Qt bug
+ // work around Qt bug: Qt4 does not release the heap allocated memory
clear(true);
return false;
}
@@ -164,15 +164,6 @@
}
//-------------------------------------------------------------------------------------------
-void AsciiFileData::release()
-{
- _array.clear();
- _begin = -1;
- _bytesRead = 0;
-}
-
-
-//-------------------------------------------------------------------------------------------
void AsciiFileData::read(QFile& file, int start, int bytesToRead, int maximalBytes)
{
_begin = -1;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifiledata.h #1320711:1320712
@@ -58,7 +58,6 @@
bool resize(int size);
void clear(bool forceDeletingArray = false);
- void release();
inline int rowBegin() const { return _rowBegin; }
inline int rowsRead() const { return _rowsRead; }
More information about the Kst
mailing list