Welcome! Log In Create A New Profile

Advanced

Free unused large block when doubling capacity of ngx_array_t.

Yousong Zhou
July 12, 2013 07:12AM
# HG changeset patch
# User Yousong Zhou <yszhou4tech@gmail.com>
# Date 1373358378 -28800
# Branch t
# Node ID b8a53d0bb5c306b89eef767694fcf127a0da8f41
# Parent 626f288fa5ede7ee3cbeffe950cb9dd611e10c52
Free unused large block when doubling capacity of ngx_array_t.

When `nalloc' of array needs to be doubled, originally allocated large
block should be freed. This can lead to gains from 2 aspects:

- It saves unnessary memory consumption.
- Length of p->large chain could be constrained a little to reduce
transversal cost.

diff -r 626f288fa5ed -r b8a53d0bb5c3 src/core/ngx_array.c
--- a/src/core/ngx_array.c Fri Jul 05 11:42:25 2013 +0400
+++ b/src/core/ngx_array.c Tue Jul 09 16:26:18 2013 +0800
@@ -79,6 +79,7 @@
}

ngx_memcpy(new, a->elts, size);
+ ngx_pfree(p, a->elts);
a->elts = new;
a->nalloc *= 2;
}
@@ -129,6 +130,7 @@
}

ngx_memcpy(new, a->elts, a->nelts * a->size);
+ ngx_pfree(p, a->elts);
a->elts = new;
a->nalloc = nalloc;
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Free unused large block when doubling capacity of ngx_array_t.

Yousong Zhou 789 July 12, 2013 07:12AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 110
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready