diff --git a/minisat/utils/ParseUtils.h b/minisat/utils/ParseUtils.h index d3071649..f31fb9ec 100644 --- a/minisat/utils/ParseUtils.h +++ b/minisat/utils/ParseUtils.h @@ -26,27 +26,34 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA #include +#include "minisat/mtl/XAlloc.h" + namespace Minisat { //------------------------------------------------------------------------------------------------- // A simple buffered character stream class: -static const int buffer_size = 1048576; class StreamBuffer { - gzFile in; - unsigned char buf[buffer_size]; - int pos; - int size; + gzFile in; + unsigned char* buf; + int pos; + int size; + + enum { buffer_size = 64*1024 }; void assureLookahead() { if (pos >= size) { pos = 0; - size = gzread(in, buf, sizeof(buf)); } } + size = gzread(in, buf, buffer_size); } } public: - explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0) { assureLookahead(); } + explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0){ + buf = (unsigned char*)xrealloc(NULL, buffer_size); + assureLookahead(); + } + ~StreamBuffer() { free(buf); } int operator * () const { return (pos >= size) ? EOF : buf[pos]; } void operator ++ () { pos++; assureLookahead(); }