Update of /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc
In directory
23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv1094/lib-src/libnyquist/nyquist/nyqsrc
Modified Files:
falloc.c falloc.h
Log Message:
Added sample block tracking so that they can be freed at Nyquist cleanup
time...watch your memory usage drop back down after applying a Nyquist effect
on a longish bit of audio.
Index: falloc.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/falloc.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- falloc.c 29 Jan 2009 18:04:21 -0000 1.1
+++ falloc.c 26 Feb 2009 03:23:16 -0000 1.2
@@ -30,10 +30,20 @@
/* memory pool */
-char *poolp = NULL;
-char *poolend = NULL;
+char *poolp;
+char *poolend;
+
+/* sample block memory pool */
+char *spoolp;
+char *spoolend;
+
int npools = 0;
+#if defined(TRACK_POOLS) && TRACK_POOLS
+#define POOL_HEAD_SIZE (round_size(sizeof(CQUE)))
+CQUE *pools = NULL;
+#endif
+
void sound_already_free_test(s)
sound_type s;
{
@@ -53,16 +63,44 @@
void new_pool(void)
{
poolp = (char *) malloc(MAXPOOLSIZE);
+
if (poolp == NULL) {
fprintf(STDERR, "fugue: out of memory!\n");
EXIT(1);
}
+
poolend = poolp + MAXPOOLSIZE;
npools++;
/* stick to double word boundaries */
poolp = (char *) round_size(((long) poolp));
}
+/* new_pool -- allocate a new pool from which mem is allocated */
+/**/
+void new_spool(void)
+{
+#if defined(TRACK_POOLS) && TRACK_POOLS
+ spoolp = (char *) malloc(MAXSPOOLSIZE + POOL_HEAD_SIZE);
+#else
+ spoolp = (char *) malloc(MAXSPOOLSIZE);
+#endif
+
+ if (spoolp == NULL) {
+ fprintf(STDERR, "fugue: out of memory!\n");
+ EXIT(1);
+ }
+
+#if defined(TRACK_POOLS) && TRACK_POOLS
+ Qenter(pools, spoolp);
+ spoolp += POOL_HEAD_SIZE;
+#endif
+
+ spoolend = spoolp + MAXSPOOLSIZE;
+ npools++;
+ /* stick to double word boundaries */
+ spoolp = (char *) round_size(((long) spoolp));
+}
+
/* find_sample_block -- get sample block when freelist is empty */
/* Try these strategies in order:
@@ -78,10 +116,10 @@
{
sample_block_type sp;
if (sample_block_total < sample_block_low_water + BLOCKS_PER_GC &&
- check_pool(round_size(sizeof(sample_block_node)))) {
- if (DEBUG_MEM) poolp += DEBUG_MEM_INFO_SIZE;
- sp = (sample_block_type) poolp;
- poolp += round_size(sizeof(sample_block_node));
+ check_spool(round_size(sizeof(sample_block_node)))) {
+ if (DEBUG_MEM) spoolp += DEBUG_MEM_INFO_SIZE;
+ sp = (sample_block_type) spoolp;
+ spoolp += round_size(sizeof(sample_block_node));
sample_block_total++;
/* printf("fp%d ", sample_block_total - sample_block_low_water); */
} else {
@@ -91,19 +129,19 @@
if (!Qempty(sample_block_free)) {
Qget(sample_block_free, sample_block_type, sp);
/* printf("gc, then from freelist\n"); */
- } else if (check_pool(round_size(sizeof(sample_block_node)))) {
- if (DEBUG_MEM) poolp += DEBUG_MEM_INFO_SIZE;
- sp = (sample_block_type) poolp;
- poolp += sizeof(sample_block_node);
+ } else if (check_spool(round_size(sizeof(sample_block_node)))) {
+ if (DEBUG_MEM) spoolp += DEBUG_MEM_INFO_SIZE;
+ sp = (sample_block_type) spoolp;
+ spoolp += round_size(sizeof(sample_block_node));
sample_block_total++;
-/* printf("gc, then from pool\n"); */
+/* printf("gc, then from spool\n"); */
} else {
- new_pool();
- if (DEBUG_MEM) poolp += DEBUG_MEM_INFO_SIZE;
- sp = (sample_block_type) poolp;
- poolp += round_size(sizeof(sample_block_node));
+ new_spool();
+ if (DEBUG_MEM) spoolp += DEBUG_MEM_INFO_SIZE;
+ sp = (sample_block_type) spoolp;
+ spoolp += round_size(sizeof(sample_block_node));
sample_block_total++;
-/* printf("gc, then new pool\n"); */
+/* printf("gc, then new spool\n"); */
}
}
return sp;
@@ -124,3 +162,94 @@
}
+#if defined(TRACK_POOLS) && TRACK_POOLS
+
+/* falloc_gc -- return empty pools to the system */
+/**/
+void falloc_gc()
+{
+ CQUE *lp = NULL;
+ CQUE *cp;
+ CQUE *np;
+ CQUE *tlist = NULL;
+
+ /* Scan all allocated pools */
+ for (cp = pools; cp; lp = cp, cp = np) {
+ char *str = ((char *)cp) + POOL_HEAD_SIZE;
+ char *end = str + MAXSPOOLSIZE;
+ long tsiz = end - str;
+ long csiz = 0;
+ CQUE *tsave = NULL;
+ CQUE *ln = NULL;
+ CQUE *cn;
+ CQUE *nn;
+
+ /* Save pointer to next pool */
+ np = cp->qnext;
+
+ /* Remember head of temp free list */
+ tsave = tlist;
+
+ /* Scan all nodes on the free list */
+ for (cn = sample_block_free; cn; ln = cn, cn = nn) {
+
+ /* Get next node */
+ nn = cn->qnext;
+
+ /* Count it if the node belongs to this pool */
+ if (cn >= (CQUE *) str && cn <= (CQUE *) end) {
+ csiz += round_size(sizeof(sample_block_node));
+
+ Qenter(tlist, cn);
+
+ /* Unlink the node */
+ if (cn == sample_block_free) {
+ sample_block_free = nn;
+ cn = NULL;
+ }
+ else {
+ ln->qnext = nn;
+ cn = ln;
+ }
+ }
+ }
+
+ /* The pool had inuse nodes */
+ if (csiz != tsiz) {
+ continue;
+ }
+
+ /* Remove the nodes from the temp free list */
+ tlist = tsave;
+
+ /* Maintain stats */
+ sample_block_total -= (tsiz / round_size(sizeof(sample_block_node)));
+ npools--;
+
+ /* If this is the active pool, then reset current pointers */
+ if (spoolp >= str && spoolp <= end) {
+ spoolp = NULL;
+ spoolend = NULL;
+ }
+
+ /* Release the pool to the system */
+ free(cp);
+
+ /* Unlink this pool from the list */
+ if (cp == pools) {
+ pools = np;
+ cp = NULL;
+ }
+ else {
+ lp->qnext = np;
+ cp = lp;
+ }
+ }
+
+ /* Resave list of free nodes */
+ sample_block_free = tlist;
+}
+
+#endif
+
+
Index: falloc.h
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/falloc.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- falloc.h 29 Jan 2009 18:04:21 -0000 1.1
+++ falloc.h 26 Feb 2009 03:23:16 -0000 1.2
@@ -56,7 +56,7 @@
#include "cque.h"
#include "debug.h"
-#define DEBUG_MEM 1
+#define DEBUG_MEM 0
#define DEBUG_MEM_INFO_SIZE (sizeof(long) + sizeof(char *))
/* special free lists */
@@ -73,15 +73,31 @@
#define MAXLISTS 128
extern CQUE *generic_free[MAXLISTS];
-/* memory pool */
+/* general memory pool */
#define MAXPOOLSIZE 1000000
extern char *poolp;
extern char *poolend;
+
+/* sample block memory pool */
+#define MAXSPOOLSIZE (256 * round_size(sizeof(sample_block_node)))
+extern char *spoolp;
+extern char *spoolend;
+
extern int npools;
extern int sample_blocks_since_gc;
+#if !defined(TRACK_POOLS)
+#define TRACK_POOLS 1
+#endif
+
+#if defined(TRACK_POOLS) && TRACK_POOLS
+extern CQUE *spools;
+void falloc_gc();
+#endif
+
void falloc_init(void);
void new_pool(void);
+void new_spool(void);
sample_block_type find_sample_block(void);
char *get_from_pool(size_t siz);
@@ -91,8 +107,10 @@
/* check_pool -- returns true if enough bytes are available */
#if DEBUG_MEM
#define check_pool(size) (poolp + (size) + DEBUG_MEM_INFO_SIZE <= poolend)
+#define check_spool(size) (spoolp + (size) + DEBUG_MEM_INFO_SIZE <= spoolend)
#else
#define check_pool(size) (poolp + (size) <= poolend)
+#define check_spool(size) (spoolp + (size) <= spoolend)
#endif
#define BLOCKS_PER_GC 100
@@ -116,7 +134,6 @@
sample_block_used--; \
}
-
#define frelease_sample_block(sp, who) { \
sp->refcnt--; \
if (DEBUG_MEM) dbg_mem_released(sp, who); \
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs