Skip to content

Commit

Permalink
Don't allocate StreamBuffers on the stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasso committed May 6, 2011
1 parent 4c4b466 commit 3652e21
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions minisat/utils/ParseUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,34 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA

#include <zlib.h>

#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(); }
Expand Down

0 comments on commit 3652e21

Please sign in to comment.