this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Bugfixes provided by: 7 * Zandra Norman 8 * 9 * Copyright: 10 * Christian Schulte, 2008 11 * 12 * This file is part of Gecode, the generic constraint 13 * development environment: 14 * http://www.gecode.org 15 * 16 * Permission is hereby granted, free of charge, to any person obtaining 17 * a copy of this software and associated documentation files (the 18 * "Software"), to deal in the Software without restriction, including 19 * without limitation the rights to use, copy, modify, merge, publish, 20 * distribute, sublicense, and/or sell copies of the Software, and to 21 * permit persons to whom the Software is furnished to do so, subject to 22 * the following conditions: 23 * 24 * The above copyright notice and this permission notice shall be 25 * included in all copies or substantial portions of the Software. 26 * 27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 31 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 32 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 33 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 * 35 */ 36 37#ifndef GECODE_FREELIST_SIZE_MAX32 38#define GECODE_FREELIST_SIZE_MAX32 3 39#endif 40#ifndef GECODE_FREELIST_SIZE_MAX64 41#define GECODE_FREELIST_SIZE_MAX64 3 42#endif 43 44namespace Gecode { namespace Kernel { 45 46 /** 47 * \brief Parameters defining memory management policy for spaces 48 * \ingroup FuncMemSpace 49 */ 50 namespace MemoryConfig { 51 /** 52 * \brief How many heap chunks should be cached at most 53 */ 54 const unsigned int n_hc_cache = 4*4; 55 56 /** 57 * \brief Minimal size of a heap chunk requested from the OS 58 */ 59 const size_t hcsz_min = 1024; 60 /** 61 * \brief Maximal size of a heap chunk requested from the OS 62 * 63 * Maximal is not strictly true, if a contiguous memory chunk is 64 * requested that exceeds \a hcsz_max, a chunk will be allocated 65 * that fits that request. 66 */ 67 const size_t hcsz_max = 32 * 1024; 68 /** 69 * \brief Increment ratio for chunk size 70 * 71 * If a space has requested \a hcsz_inc_ratio chunks of heap memory, 72 * the chunk size is doubled. 73 */ 74 const int hcsz_inc_ratio = 8; 75 /** 76 * \brief Decrement ratio for chunk size 77 * 78 * When a space is cloned, the new clone normally inherits the 79 * current chunk size from the original space. However, if the 80 * original space has requested less than \a hcsz_dec_ratio 81 * heap chunks of the current chunk size, the current chunk size 82 * for the clone is halfed. 83 */ 84 const int hcsz_dec_ratio = 8; 85 86 /** 87 * \brief Unit size for free lists 88 * 89 * The unit size (given as binary logarithm) defines how big 90 * a unit of memory for free lists is. Also, it defines the 91 * alignment. Sizes of free list objects must be multiples of 92 * the unit size. 93 * 94 * Currently, for 32 bit machines, the unit size is 4 bytes. 95 * For 64 bit machines, it is 8 bytes. 96 */ 97 const int fl_unit_size = ((sizeof(void*) == 4) ? 2 : 3); 98 /** 99 * \brief Minimal size for free list element 100 * 101 * The minimal size is given in the number of free list units. 102 * 103 * Currently, for 32 bit machines, the minimal size is 8 bytes. 104 * For 64 bit machines, it is 16 bytes. 105 */ 106 const int fl_size_min = ((sizeof(void*) == 4) ? 2 : 2); 107 /** 108 * \brief Maximal size for free list element 109 * 110 * The maximal size is given in the number of free list units. 111 * 112 * Currently, for 32 bit machines, the maximal size is 12 bytes. 113 * For 64 bit machines, it is 24 bytes. 114 */ 115 const int fl_size_max = ((sizeof(void*) == 4) ? GECODE_FREELIST_SIZE_MAX32 : GECODE_FREELIST_SIZE_MAX64); 116 /** 117 * \brief Number of free lists elements to allocate 118 * 119 * When a request for a free list element can not be fulfilled, as 120 * the free list is empty and there is also no reusable memory 121 * available, allocate \a fl_refill free list elements. 122 */ 123 const int fl_refill = 8; 124 /** 125 * \brief Memory alignment 126 * 127 * Memory alignment is controlled by the macro GECODE_MEMORY_ALIGNMENT. 128 * If it is not defined, it assumed to be 8. Otherwise, the defined 129 * value is used. 130 */ 131#ifndef GECODE_MEMORY_ALIGNMENT 132#define GECODE_MEMORY_ALIGNMENT static_cast<size_t>(8U) 133#endif 134 /** 135 * \brief Size of region area 136 * 137 * The region area can be used in a stack fashion through access 138 * from a space. If the a request exceeds the current free space, 139 * memory will be allocated from the heap. 140 */ 141 const size_t region_area_size = 32 * 1024; 142 143 /// Align size \a s to the required alignment \a a 144 void align(size_t& s, size_t a = GECODE_MEMORY_ALIGNMENT); 145 146 /* 147 * Alignment 148 * 149 */ 150 forceinline void 151 align(size_t& s, size_t a) { 152 s += ((a - (s & (a - 1))) & (a - 1)); 153 } 154 155 } 156 157}} 158 159// STATISTICS: kernel-memory