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

Changeset 3073

Show
Ignore:
Timestamp:
01/07/08 14:34:49 (11 months ago)
Author:
sean
Message:

Added GC.reserve(size_t) as a means of telling the GC to obtain a specific amount of memory from the OS and mark it as free. This is an optimization feature intended to allow programmers to tune the performance of applications which are expected to use a specific or minimum amount of memory. Calling this routine ensures that the specified amount of memory is immediately available and no collections should occur until more than the requested number of bytes are allocated during the program run. This closes #817.

Files:

Legend:

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

    r2648 r3073  
    2727    extern (C) void*  gc_realloc( void* p, size_t sz, uint ba = 0 ); 
    2828    extern (C) size_t gc_extend( void* p, size_t mx, size_t sz ); 
     29    extern (C) size_t gc_reserve( size_t sz ); 
    2930    extern (C) void   gc_free( void* p ); 
    3031 
     
    282283 
    283284    /** 
     285     * Requests that at least sz bytes of memory be obtained from the operating 
     286     * system and marked as free. 
     287     * 
     288     * Params: 
     289     *  sz = The desired size in bytes. 
     290     * 
     291     * Returns: 
     292     *  The actual number of bytes reserved or zero on error. 
     293     */ 
     294    static size_t reserve( size_t sz ) 
     295    { 
     296        return gc_reserve( sz ); 
     297    } 
     298 
     299 
     300    /** 
    284301     * Deallocates the memory referenced by p.  If p is null, no action 
    285302     * occurs.  If p references memory not originally allocated by this 
  • trunk/lib/gc/basic/gc.d

    r2865 r3073  
    2626 
    2727private import gcx; 
     28private import gcstats; 
    2829private import tango.stdc.stdlib; 
    2930 
     
    125126} 
    126127 
     128extern (C) size_t gc_reserve( size_t sz ) 
     129{ 
     130    return _gc.reserve( sz ); 
     131} 
     132 
    127133extern (C) void gc_free( void* p ) 
    128134{ 
     
    143149{ 
    144150    return _gc.query( p ); 
     151} 
     152 
     153// NOTE: This routine is experimental.  The stats or function name may change 
     154//       before it is made officially available. 
     155extern (C) GCStats gc_stats() 
     156{ 
     157    GCStats stats; 
     158    _gc.getStats(stats); 
     159    return stats; 
    145160} 
    146161 
  • trunk/lib/gc/basic/gcx.d

    r3031 r3073  
    792792     * 
    793793     */ 
     794    size_t reserve(size_t size) 
     795    { 
     796        if (!size) 
     797        { 
     798            return 0; 
     799        } 
     800 
     801        if (!thread_needLock()) 
     802        { 
     803            return reserveNoSync(size); 
     804        } 
     805        else synchronized (gcLock) 
     806        { 
     807            return reserveNoSync(size); 
     808        } 
     809    } 
     810 
     811 
     812    // 
     813    // 
     814    // 
     815    private size_t reserveNoSync(size_t size) 
     816    { 
     817        assert(size != 0); 
     818        assert(gcx); 
     819 
     820        return gcx.reserve(size); 
     821    } 
     822 
     823 
     824    /** 
     825     * 
     826     */ 
    794827    void free(void *p) 
    795828    { 
     
    17811814        } 
    17821815        return bin; 
     1816    } 
     1817 
     1818 
     1819    /** 
     1820     * Allocate a new pool of at least size bytes. 
     1821     * Sort it into pooltable[]. 
     1822     * Mark all memory in the pool as B_FREE. 
     1823     * Return the actual number of bytes reserved or 0 on error. 
     1824     */ 
     1825    size_t reserve(size_t size) 
     1826    { 
     1827        uint npages = (size + PAGESIZE - 1) / PAGESIZE; 
     1828        Pool *pool = newPool(npages); 
     1829 
     1830        if (!pool || pool.extendPages(npages) == ~0u) 
     1831            return 0; 
     1832        return pool.ncommitted * PAGESIZE; 
    17831833    } 
    17841834