Skip to content

Commit

Permalink
Merge pull request #8279 from bendavid/lhexmlmemoryimproved_75x
Browse files Browse the repository at this point in the history
improve memory allocation strategy in lhe blob compression
  • Loading branch information
cmsbuild committed Mar 14, 2015
2 parents 12fa48a + e17afc5 commit b209b15
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion SimDataFormats/GeneratorProducts/src/LHEXMLStringProduct.cc
Expand Up @@ -34,6 +34,8 @@ void LHEXMLStringProduct::fillCompressedContent(std::istream &input, unsigned in
constexpr unsigned int bufsize = 4096;
char inbuf[bufsize];

const unsigned int threshsize = 32*1024*1024;

//initialize lzma
uint32_t preset = 9;
lzma_stream strm = LZMA_STREAM_INIT;
Expand Down Expand Up @@ -69,7 +71,12 @@ void LHEXMLStringProduct::fillCompressedContent(std::istream &input, unsigned in
//if output blob is full and compression is still going, allocate more memory
if (strm.avail_out == 0 && ret==LZMA_OK) {
unsigned int oldsize = output.size();
output.resize(2*oldsize);
if (oldsize<threshsize) {
output.resize(2*oldsize);
}
else {
output.resize(oldsize + threshsize);
}
strm.next_out = &output[oldsize];
strm.avail_out = output.size() - oldsize;
}
Expand Down

0 comments on commit b209b15

Please sign in to comment.