From: Heng Li Date: Fri, 30 Mar 2012 02:27:57 +0000 (-0400) Subject: shrink bam1_t::m_data when sorting X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=0f2614cfa1db19990246c91e776ca280213d1940 shrink bam1_t::m_data when sorting Otherwise most of allocated memory may not be used --- diff --git a/bam.h b/bam.h index 11f8028..efc0459 100644 --- 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 #include diff --git a/bam_sort.c b/bam_sort.c index c451dcf..7d00cd1 100644 --- a/bam_sort.c +++ b/bam_sort.c @@ -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) {