]> git.donarmstrong.com Git - samtools.git/commitdiff
shrink bam1_t::m_data when sorting
authorHeng Li <lh3@me.com>
Fri, 30 Mar 2012 02:27:57 +0000 (22:27 -0400)
committerHeng Li <lh3@me.com>
Fri, 30 Mar 2012 02:27:57 +0000 (22:27 -0400)
Otherwise most of allocated memory may not be used

bam.h
bam_sort.c

diff --git a/bam.h b/bam.h
index 11f8028cf6d96ece1390074c6fb155437ce5f766..efc0459626b1ddb564bb7b4eb368a26fa70fc5ea 100644 (file)
--- a/bam.h
+++ b/bam.h
@@ -40,7 +40,7 @@
   @copyright Genome Research Ltd.
  */
 
-#define BAM_VERSION "0.1.18-dev (r982:313)"
+#define BAM_VERSION "0.1.18-master-r567"
 
 #include <stdint.h>
 #include <stdlib.h>
index c451dcf63bcafa49563aefd2819c07bc6a1f5ddc..7d00cd1a83321729c1384cf56f066d2c83f65548 100644 (file)
@@ -472,6 +472,11 @@ void bam_sort_core_ext(int is_by_qname, const char *fn, const char *prefix, size
                if (buf[k] == 0) buf[k] = (bam1_t*)calloc(1, sizeof(bam1_t));
                b = buf[k];
                if ((ret = bam_read1(fp, b)) < 0) break;
+               if (b->data_len < b->m_data>>2) { // shrink
+                       b->m_data = b->data_len;
+                       kroundup32(b->m_data);
+                       b->data = realloc(b->data, b->m_data);
+               }
                mem += sizeof(bam1_t) + b->m_data + sizeof(void*) + sizeof(void*); // two sizeof(void*) for the data allocated to pointer arrays
                ++k;
                if (mem >= max_mem) {