Changeset 3155
- Timestamp:
- 02/07/08 22:21:44 (10 months ago)
- Files:
-
- trunk/lib/common/tango/core/Memory.d (modified) (2 diffs)
- trunk/lib/gc/basic/gc.d (modified) (1 diff)
- trunk/lib/gc/basic/gcx.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/common/tango/core/Memory.d
r3145 r3155 18 18 extern (C) void gc_disable(); 19 19 extern (C) void gc_collect(); 20 extern (C) void gc_minimize(); 20 21 21 22 extern (C) uint gc_getAttr( void* p ); … … 88 89 { 89 90 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(); 90 101 } 91 102 trunk/lib/gc/basic/gc.d
r3078 r3155 91 91 } 92 92 93 94 extern (C) void gc_minimize() 95 { 96 _gc.minimize(); 97 } 98 93 99 extern (C) uint gc_getAttr( void* p ) 94 100 { trunk/lib/gc/basic/gcx.d
r3078 r3155 1259 1259 1260 1260 /** 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 /** 1261 1277 * Retrieve statistics about garbage collection. 1262 1278 * Useful for debugging and tuning. … … 1840 1856 1841 1857 /** 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 /** 1842 1893 * Allocate a chunk of memory that is larger than a page. 1843 1894 * Return null if out of memory. … … 1882 1933 continue; 1883 1934 } 1935 // Release empty pools to prevent bloat 1936 minimize(); 1884 1937 // Allocate new pool 1885 1938 pool = newPool(npages); … … 1892 1945 goto L1; 1893 1946 case 1: 1947 // Release empty pools to prevent bloat 1948 minimize(); 1894 1949 // Allocate new pool 1895 1950 pool = newPool(npages);












