From 4c797d57d0ce45532e1fd3dc144ba271f2f5f86c Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 21 Jul 2009 09:39:58 +0000 Subject: Use a BufferedReadStream to buffer ArjFile's input to reduce memory usage svn-id: r42637 --- common/unarj.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/unarj.cpp b/common/unarj.cpp index 428b4a426e..0312cc5b08 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -105,7 +105,7 @@ public: void decode(int32 origsize); void decode_f(int32 origsize); - MemoryReadStream *_compressed; + BufferedReadStream *_compressed; MemoryWriteStream *_outstream; //protected: @@ -360,6 +360,9 @@ bool ArjFile::open(const Common::String &filename) { return false; ArjHeader *hdr = _headers[_fileMap[filename]]; + + // TODO: It would be good if ArjFile could decompress files in a streaming + // mode, so it would not need to pre-allocate the entire output. byte *uncompressedData = (byte *)malloc(hdr->origSize); File archiveFile; @@ -372,10 +375,11 @@ bool ArjFile::open(const Common::String &filename) { } else { ArjDecoder *decoder = new ArjDecoder(hdr); - byte *compressedData = (byte *)malloc(hdr->compSize); - archiveFile.read(compressedData, hdr->compSize); - - decoder->_compressed = new MemoryReadStream(compressedData, hdr->compSize, true); + // TODO: It might not be appropriate to use this wrapper inside ArjFile. + // If reading from archiveFile directly is too slow to be usable, + // maybe the filesystem code should instead wrap its files + // in a BufferedReadStream. + decoder->_compressed = new BufferedReadStream(&archiveFile, 4096, false); decoder->_outstream = new MemoryWriteStream(uncompressedData, hdr->origSize); if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3) -- cgit v1.2.3