Gets a pointer to a new array, acquired from the shared resources pool.
Gets a new void[] wrapped with an API allowing it to be used as a T[], acquired from the shared resources pool.
Initialises this instance. (No other methods may be called before calling this method.)
Relinquishes all shared resources acquired by this instance.
element type of the arrays
1 // Demonstrates how a typical global shared resources container should look. 2 // A single instance of this would be owned at the top level of the app. 3 class SharedResources 4 { 5 import ocean.util.container.pool.FreeList; 6 7 // The pool of untyped buffers required by AcquiredArraysOf. 8 private FreeList!(ubyte[]) buffers; 9 10 this ( ) 11 { 12 this.buffers = new FreeList!(ubyte[]); 13 } 14 15 // Objects of this class will be newed at scope and passed to execution 16 // contexts. This allows the context to acquire various shared resources 17 // and have them automatically relinquished when it exits. 18 class ContextResources 19 { 20 // Tracker of buffers acquired by the context. 21 private AcquiredArraysOf!(void) acquired_void_buffers; 22 23 // Initialise the tracker in the ctor. 24 this ( ) 25 { 26 this.acquired_void_buffers.initialise(this.outer.buffers); 27 } 28 29 // ...and be sure to relinquish all the acquired resources in the 30 // dtor. 31 ~this ( ) 32 { 33 this.acquired_void_buffers.relinquishAll(); 34 } 35 36 // Public method to get a new resource, managed by the tracker. 37 public void[]* getVoidBuffer ( ) 38 { 39 return this.acquired_void_buffers.acquire(); 40 } 41 } 42 } 43 44 // Demonstrates the usage of the shared resources and the context resources. 45 class Context 46 { 47 SharedResources resources; 48 49 void entryPoint ( ) 50 { 51 // New a ContextResources as scope, so that its dtor will be called 52 // at scope exit and all acquired resources relinquished. 53 scope acquired = this.resources.new ContextResources; 54 55 // Acquire some buffers. 56 auto buf1 = acquired.getVoidBuffer(); 57 auto buf2 = acquired.getVoidBuffer(); 58 auto buf3 = acquired.getVoidBuffer(); 59 } 60 }
Set of acquired arrays of the templated type acquired by an execution context. An external source of untyped arrays -- a FreeList!(ubyte[]) -- is required. When arrays are acquired (via the acquire() method), they are requested from the free list and stored internally in a container array. When the arrays are no longer required, the relinquishAll() method will return them to the free list. Note that the container array used to store the acquired arrays is also itself acquired from the free list and relinquished by relinquishAll().