Skip to content

Commit

Permalink
Avoid allocating too little memory and too often
Browse files Browse the repository at this point in the history
  • Loading branch information
fdmanana committed Apr 3, 2011
1 parent af8de87 commit 3e9a54b
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions c_src/snappy.cc
Expand Up @@ -27,8 +27,6 @@
#endif


const size_t ALLOC_SIZE = 2048;

class OutOfMem {};


Expand All @@ -50,7 +48,7 @@ class SnappyNifSink : public snappy::Sink {

char* GetAppendBuffer(size_t len, char* scratch) {
if ((length + len) > bin.size) {
size_t sz = len > ALLOC_SIZE ? len + ALLOC_SIZE - (len % ALLOC_SIZE) : ALLOC_SIZE;
size_t sz = (len * 4) < 8192 ? 8192 : (len * 4);

if (!enif_realloc_binary_compat(env, &bin, bin.size + sz)) {
enif_release_binary_compat(env, &bin);
Expand Down

0 comments on commit 3e9a54b

Please sign in to comment.