Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3155

Show
Ignore:
Timestamp:
02/07/08 22:21:44 (10 months ago)
Author:
sean
Message:

Added GC.minimize(), which returns the memory used by empty pools back to the OS. This routine is also called within Gcx.bigAlloc() after a collection has failed to produce a sufficient block of memory for the allocation, and before a new pool is created. This closes #878

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/common/tango/core/Memory.d

    r3145 r3155  
    1818    extern (C) void gc_disable(); 
    1919    extern (C) void gc_collect(); 
     20    extern (C) void gc_minimize(); 
    2021 
    2122    extern (C) uint gc_getAttr( void* p ); 
     
    8889    { 
    8990        gc_collect(); 
     91    } 
     92 
     93    /** 
     94     * Indicates that the managed memory space be minimized by returning free 
     95     * physical memory to the operating system.  The amount of free memory 
     96     * returned depends on the allocator design and on program behavior. 
     97     */ 
     98    static void minimize() 
     99    { 
     100        gc_minimize(); 
    90101    } 
    91102 
  • trunk/lib/gc/basic/gc.d

    r3078 r3155  
    9191} 
    9292 
     93 
     94extern (C) void gc_minimize() 
     95{ 
     96    _gc.minimize(); 
     97} 
     98 
    9399extern (C) uint gc_getAttr( void* p ) 
    94100{ 
  • trunk/lib/gc/basic/gcx.d

    r3078 r3155  
    12591259 
    12601260    /** 
     1261     * minimize free space usage 
     1262     */ 
     1263    void minimize() 
     1264    { 
     1265        if (!thread_needLock()) 
     1266        { 
     1267            gcx.minimize(); 
     1268        } 
     1269        else synchronized (gcLock) 
     1270        { 
     1271            gcx.minimize(); 
     1272        } 
     1273    } 
     1274 
     1275 
     1276    /** 
    12611277     * Retrieve statistics about garbage collection. 
    12621278     * Useful for debugging and tuning. 
     
    18401856 
    18411857    /** 
     1858     * Minimizes physical memory usage by returning free pools to the OS. 
     1859     */ 
     1860    void minimize() 
     1861    { 
     1862        size_t n; 
     1863        size_t pn; 
     1864        Pool*  pool; 
     1865        size_t ncommitted; 
     1866 
     1867        for (n = 0; n < npools; n++) 
     1868        { 
     1869            pool = pooltable[n]; 
     1870            ncommitted = pool.ncommitted; 
     1871            for (pn = 0; pn < ncommitted; pn++) 
     1872            { 
     1873                if (cast(Bins)pool.pagetable[pn] != B_FREE) 
     1874                    break; 
     1875            } 
     1876            if (pn < ncommitted) 
     1877            { 
     1878                n++; 
     1879                continue; 
     1880            } 
     1881            pool.Dtor(); 
     1882            cstdlib.free(pool); 
     1883            cstring.memmove(pooltable + n, 
     1884                            pooltable + n + 1, 
     1885                            (--npools - n) * (Pool*).sizeof); 
     1886            minAddr = pooltable[0].baseAddr; 
     1887            maxAddr = pooltable[npools - 1].topAddr; 
     1888        } 
     1889    } 
     1890 
     1891 
     1892    /** 
    18421893     * Allocate a chunk of memory that is larger than a page. 
    18431894     * Return null if out of memory. 
     
    18821933                    continue; 
    18831934                } 
     1935                // Release empty pools to prevent bloat 
     1936                minimize(); 
    18841937                // Allocate new pool 
    18851938                pool = newPool(npages); 
     
    18921945                goto L1; 
    18931946            case 1: 
     1947                // Release empty pools to prevent bloat 
     1948                minimize(); 
    18941949                // Allocate new pool 
    18951950                pool = newPool(npages);