Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
replace removal with linear time semi-stable partition
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Dec 6, 2011
1 parent 1b89380 commit 17a7c8e
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions src/gc/gcx.d
Expand Up @@ -2014,24 +2014,44 @@ struct Gcx
void minimize()
{
debug(PRINTF) printf("Minimizing.\n");
size_t n;
size_t pn;
Pool* pool;
size_t ncommitted;

Outer:
for (n = 0; n < npools; n++)
static bool isUsed(Pool *pool)
{
pool = pooltable[n];
debug(PRINTF) printFreeInfo(pool);
if(pool.freepages < pool.npages) continue;
pool.Dtor();
cstdlib.free(pool);
memmove(pooltable + n,
pooltable + n + 1,
(--npools - n) * (Pool*).sizeof);
n--;
return pool.freepages < pool.npages;
}

// semi-stable partition
for (size_t i = 0; i < npools; ++i)
{
auto pool = pooltable[i];
// find first unused pool
if (isUsed(pool)) continue;

// move used pools before unused ones
size_t j = i + 1;
for (; j < npools; ++j)
{
pool = pooltable[j];
if (!isUsed(pool)) continue;
// swap
pooltable[j] = pooltable[i];
pooltable[i] = pool;
++i;
}
// npooltable[0 .. i] => used
// npooltable[i .. npools] => free

// free unused pools
for (j = i; j < npools; ++j)
{
pool = pooltable[j];
debug(PRINTF) printFreeInfo(pool);
pool.Dtor();
cstdlib.free(pool);
}
npools = i;
}

if (npools)
{
minAddr = pooltable[0].baseAddr;
Expand Down

0 comments on commit 17a7c8e

Please sign in to comment.