From 64d9eb5d2c5daee592ab723effbdeb81db02b3d1 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Sat, 11 Oct 2014 18:04:05 +0100 Subject: [PATCH] Add totalsize and freesize methods for snc. Copied from Perforce Change: 187215 ServerID: perforce.ravenbrook.com --- mps/code/poolsnc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/mps/code/poolsnc.c b/mps/code/poolsnc.c index df2d964340b..6bdf4597064 100644 --- a/mps/code/poolsnc.c +++ b/mps/code/poolsnc.c @@ -663,6 +663,52 @@ static void SNCWalk(Pool pool, Seg seg, FormattedObjectsVisitor f, } +/* SNCTotalSize -- total memory allocated from the arena */ + +static Size SNCTotalSize(Pool pool) +{ + SNC snc; + Ring ring, node, nextNode; + Size total = 0; + + AVERT(Pool, pool); + snc = PoolSNC(pool); + AVERT(SNC, snc); + + ring = &pool->segRing; + RING_FOR(node, ring, nextNode) { + Seg seg = SegOfPoolRing(node); + AVERT(Seg, seg); + total += SegSize(seg); + } + + return total; +} + + +/* SNCFreeSize -- free memory (unused by client program) */ + +static Size SNCFreeSize(Pool pool) +{ + SNC snc; + Seg seg; + Size free = 0; + + AVERT(Pool, pool); + snc = PoolSNC(pool); + AVERT(SNC, snc); + + seg = snc->freeSegs; + while (seg != NULL) { + AVERT(Seg, seg); + free += SegSize(seg); + seg = sncSegNext(seg); + } + + return free; +} + + /* SNCPoolClass -- the class definition */ DEFINE_POOL_CLASS(SNCPoolClass, this) @@ -683,6 +729,8 @@ DEFINE_POOL_CLASS(SNCPoolClass, this) this->framePopPending = SNCFramePopPending; this->walk = SNCWalk; this->bufferClass = SNCBufClassGet; + this->totalSize = SNCTotalSize; + this->freeSize = SNCFreeSize; AVERT(PoolClass, this); }