1 /******************************************************************************* 2 3 A bucket element allocator using the D runtime memory manager. Bucket 4 elements are newed by get() and deleted by recycle(). 5 6 Copyright: 7 Copyright (c) 2009-2016 dunnhumby Germany GmbH. 8 All rights reserved. 9 10 License: 11 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 12 Alternatively, this file may be distributed under the terms of the Tango 13 3-Clause BSD License (see LICENSE_BSD.txt for details). 14 15 *******************************************************************************/ 16 17 module ocean.util.container.map.model.BucketElementGCAllocator; 18 19 20 import ocean.util.container.map.model.IBucketElementGCAllocator; 21 22 23 /******************************************************************************* 24 25 A bucket element allocator using the D runtime memory manager. Even though 26 this memory manager is called "GC-managed" this class 27 in fact doesn't rely on garbage collection but explicitly deletes unused 28 bucket elements. 29 30 *******************************************************************************/ 31 32 public class BucketElementGCAllocator(Bucket) : IBucketElementGCAllocator 33 { 34 /*************************************************************************** 35 36 Constructor. 37 38 ***************************************************************************/ 39 40 public this ( ) 41 { 42 super(Bucket.Element.sizeof); 43 } 44 45 /*************************************************************************** 46 47 Gets or allocates an object 48 49 Returns: 50 an object that is ready to use. 51 52 ***************************************************************************/ 53 54 protected override void* allocate ( ) 55 { 56 return new Bucket.Element; 57 } 58 } 59 60 61 /******************************************************************************* 62 63 Creates an instance of BucketElementGCAllocator which is suitable for usage 64 with the Map type passed as a template parameter. 65 66 Params: 67 Map = the type to create the allocator according to 68 69 Returns: 70 an instance of type BucketElementGCAllocator class 71 72 *******************************************************************************/ 73 74 public BucketElementGCAllocator!(Map.Bucket) instantiateAllocator ( Map ) ( ) 75 { 76 return new BucketElementGCAllocator!(Map.Bucket); 77 }