From 015503bde3d5bfb125231f8ef096419a741672fb Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 15 Nov 2008 16:51:58 +0000 Subject: [PATCH] trigger GCs based on number of allocated bitmaps under Windows, not just their sizes svn: r12457 --- src/wxcommon/wxGC.cxx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/wxcommon/wxGC.cxx b/src/wxcommon/wxGC.cxx index 31faa718c3..31f523775d 100644 --- a/src/wxcommon/wxGC.cxx +++ b/src/wxcommon/wxGC.cxx @@ -374,7 +374,11 @@ char *gc::gcGetName() { forces a GC more frequently than might otherwise happen as the total size of bitmaps grows. */ -static long total, accum = 1024 * 1024 * 5; +#define INIT_ACCUM_SIZE 1024 * 1024 * 5 +#define INIT_ACCUM_COUNT 1000 + +static long total, accum = INIT_ACCUM_SIZE; +static int total_count, accum_count = INIT_ACCUM_COUNT; void *GC_malloc_accounting_shadow(long a) { @@ -383,10 +387,24 @@ void *GC_malloc_accounting_shadow(long a) a = sizeof(long); total += a; accum -= a; + total_count += 1; + accum_count -= 1; if (accum <= 0) { GC_gcollect(); accum = total >> 1; + if (accum < INIT_ACCUM_SIZE) + accum = INIT_ACCUM_SIZE; } +#ifdef wx_msw + /* Under Windows, the number of bitmaps matters, even if + they're small. */ + if (accum_count <= 0) { + GC_gcollect(); + accum_count = total_count >> 1; + if (accum_count < INIT_ACCUM_COUNT) + accum_count = INIT_ACCUM_COUNT; + } +#endif p = (long *)GC_malloc_atomic(a); *p = a; return (void *)p; @@ -397,5 +415,7 @@ void GC_free_accounting_shadow(void *p) if (p) { total -= *(long *)p; accum += *(long *)p; + total_count -= 1; + accum_count += 1; } }