summaryrefslogtreecommitdiff
path: root/src/SingleFileAllocationIterator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/SingleFileAllocationIterator.cc')
-rw-r--r--src/SingleFileAllocationIterator.cc47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc
index 1384c163..620410fa 100644
--- a/src/SingleFileAllocationIterator.cc
+++ b/src/SingleFileAllocationIterator.cc
@@ -33,35 +33,42 @@
*/
/* copyright --> */
#include "SingleFileAllocationIterator.h"
-#include "AbstractSingleDiskAdaptor.h"
+#include "BinaryStream.h"
+#include "Util.h"
+#include "a2io.h"
-#define BUFSIZE 16*1024
+#define BUFSIZE (256*1024)
-SingleFileAllocationIterator::SingleFileAllocationIterator(AbstractSingleDiskAdaptor* diskAdaptor):_diskAdaptor(diskAdaptor), _offset(diskAdaptor->size()) {}
+SingleFileAllocationIterator::SingleFileAllocationIterator(BinaryStream* stream, int64_t offset, int64_t totalLength):_stream(stream), _offset(offset), _totalLength(totalLength), _buffer(0)
+{}
-SingleFileAllocationIterator::~SingleFileAllocationIterator() {}
+SingleFileAllocationIterator::~SingleFileAllocationIterator()
+{
+ delete [] _buffer;
+}
-void SingleFileAllocationIterator::allocateChunk()
+void SingleFileAllocationIterator::init()
{
- int32_t bufSize = BUFSIZE;
- unsigned char buf[BUFSIZE];
- memset(buf, 0, bufSize);
-
- _diskAdaptor->writeData(buf, bufSize, _offset);
- _offset += bufSize;
-
- if(_diskAdaptor->getTotalLength() < _offset) {
- _diskAdaptor->truncate(getTotalLength());
- _offset = getTotalLength();
- }
+#ifdef HAVE_POSIX_MEMALIGN
+ _buffer = (unsigned char*)Util::allocateAlignedMemory(512, BUFSIZE);
+#else
+ _buffer = new unsigned char[BUFSIZE];
+#endif // HAVE_POSIX_MEMALIGN
+ memset(_buffer, 0, BUFSIZE);
}
-bool SingleFileAllocationIterator::finished()
+void SingleFileAllocationIterator::allocateChunk()
{
- return getCurrentLength() >= getTotalLength();
+ _stream->writeData(_buffer, BUFSIZE, _offset);
+ _offset += BUFSIZE;
+
+ if(_totalLength < _offset) {
+ _stream->truncate(_totalLength);
+ _offset = _totalLength;
+ }
}
-int64_t SingleFileAllocationIterator::getTotalLength()
+bool SingleFileAllocationIterator::finished()
{
- return _diskAdaptor->getTotalLength();
+ return _offset >= _totalLength;
}