41438a0bfd68335a15a262cf54ff49e32ea0e4a1
braney
  Tue Aug 17 12:56:43 2010 -0700
change code that was allocating a 13mb array on the stack to use a scratch area instead
diff --git src/utils/bedToBigBed/bedToBigBed.c src/utils/bedToBigBed/bedToBigBed.c
index d1bf53c..db6f8ee 100644
--- src/utils/bedToBigBed/bedToBigBed.c
+++ src/utils/bedToBigBed/bedToBigBed.c
@@ -159,7 +159,21 @@
 	if (doCompress)
 	    {
 	    size_t maxCompSize = zCompBufSize(stream->stringSize);
-	    char compBuf[maxCompSize];
+
+            // keep around an area of scratch memory
+            static int compBufSize = 0;
+            static char *compBuf = NULL;
+            // check to see if buffer needed for compression is big enough
+            if (compBufSize < maxCompSize)
+                {
+                // free up the old not-big-enough piece
+                freez(&compBuf); // freez knows bout NULL
+
+                // get new scratch area
+                compBufSize = maxCompSize;
+                compBuf = needMem(compBufSize);
+                }
+
 	    int compSize = zCompress(stream->string, stream->stringSize, compBuf, maxCompSize);
 	    mustWrite(f, compBuf, compSize);
 	    }