Mercurial > hg > svcore
comparison data/fileio/MatrixFile.cpp @ 1078:ce82bcdc95d0
Fail upfront if the file is going to be too large. We expect the caller to split up large data sets into several MatrixFiles
author | Chris Cannam |
---|---|
date | Wed, 10 Jun 2015 13:10:26 +0100 |
parents | 59e7fe1b1003 |
children | aa588c391d1a |
comparison
equal
deleted
inserted
replaced
1077:ec6e7f0f3f5b | 1078:ce82bcdc95d0 |
---|---|
87 cerr << "ERROR: MatrixFile::MatrixFile: Write-only mode " | 87 cerr << "ERROR: MatrixFile::MatrixFile: Write-only mode " |
88 << "specified, but file already exists" << endl; | 88 << "specified, but file already exists" << endl; |
89 throw FileOperationFailed(fileName, "create"); | 89 throw FileOperationFailed(fileName, "create"); |
90 } | 90 } |
91 | 91 |
92 // Use floating-point here to avoid integer overflow. We can be | |
93 // approximate so long as we are on the cautious side | |
94 if ((double(m_width) * m_height) * m_cellSize + m_headerSize + m_width >= | |
95 pow(2, 31) - 10.0) { // bit of slack there | |
96 cerr << "ERROR: MatrixFile::MatrixFile: width " << m_width | |
97 << " is too large for height " << m_height << " and cell size " | |
98 << m_cellSize << " (should be using multiple files)" << endl; | |
99 throw FileOperationFailed(fileName, "size"); | |
100 } | |
101 | |
92 m_flags = 0; | 102 m_flags = 0; |
93 m_fmode = S_IRUSR | S_IWUSR; | 103 m_fmode = S_IRUSR | S_IWUSR; |
94 | 104 |
95 if (m_mode == WriteOnly) { | 105 if (m_mode == WriteOnly) { |
96 m_flags = O_WRONLY | O_CREAT; | 106 m_flags = O_WRONLY | O_CREAT; |
201 m_setColumns = new ResizeableBitset(m_width); | 211 m_setColumns = new ResizeableBitset(m_width); |
202 | 212 |
203 off_t off = m_headerSize + (m_width * m_height * m_cellSize) + m_width; | 213 off_t off = m_headerSize + (m_width * m_height * m_cellSize) + m_width; |
204 | 214 |
205 #ifdef DEBUG_MATRIX_FILE | 215 #ifdef DEBUG_MATRIX_FILE |
206 cerr << "MatrixFile[" << m_fd << "]::initialise(" << m_width << ", " << m_height << "): cell size " << m_cellSize << ", header size " << m_headerSize << ", resizing file" << endl; | 216 cerr << "MatrixFile[" << m_fd << "]::initialise(" << m_width << ", " << m_height << "): cell size " << m_cellSize << ", header size " << m_headerSize << ", resizing fd " << m_fd << " to " << off << endl; |
207 #endif | 217 #endif |
208 | 218 |
209 if (::lseek(m_fd, off - 1, SEEK_SET) < 0) { | 219 if (::lseek(m_fd, off - 1, SEEK_SET) < 0) { |
210 ::perror("ERROR: MatrixFile::initialise: seek to end failed"); | 220 ::perror("ERROR: MatrixFile::initialise: seek to end failed"); |
211 throw FileOperationFailed(m_fileName, "lseek"); | 221 throw FileOperationFailed(m_fileName, "lseek"); |