Permalink
Browse files

Avoid allocating too little memory and too often

  • Loading branch information...
1 parent af8de87 commit 3e9a54b7908171aa9fba919220743ede1803dade @fdmanana fdmanana committed Apr 3, 2011
Showing with 1 addition and 3 deletions.
  1. +1 −3 c_src/snappy.cc
View
@@ -27,8 +27,6 @@
#endif
-const size_t ALLOC_SIZE = 2048;
-
class OutOfMem {};
@@ -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);

0 comments on commit 3e9a54b

Please sign in to comment.