41 namespace Gecode {
namespace Kernel {
117 namespace Gecode {
namespace Kernel {
141 void alloc_fill(
SharedMemory& sm,
size_t s,
bool first);
147 void* subscriptions(
void)
const;
155 static size_t sz2i(
size_t);
157 static size_t i2sz(
size_t);
171 void reuse(
void*
p,
size_t s);
176 namespace Gecode {
namespace Kernel {
190 while (
heap.hc != NULL) {
200 while ((
heap.hc != NULL) && (
heap.hc->size < l)) {
207 if (
heap.hc == NULL) {
208 assert(
heap.n_hc == 0);
265 namespace Gecode {
namespace Kernel {
273 MemoryManager::sz2i(
size_t s) {
280 MemoryManager::i2sz(
size_t i) {
298 MemoryManager::subscriptions(
void)
const {
299 return &cur_hc->area[0];
303 MemoryManager::alloc_fill(
SharedMemory& sm,
size_t sz,
bool first) {
312 size_t overhead =
sizeof(
HeapChunk) -
sizeof(
double);
315 size_t allocate = ((sz > cur_hcsz) ?
316 (((
size_t) (sz / cur_hcsz)) + 1) * cur_hcsz : cur_hcsz);
320 lsz = hc->
size - overhead;
323 requested = hc->
size;
324 hc->
next = NULL; cur_hc = hc;
326 requested += hc->
size;
329 #ifdef GECODE_MEMORY_CHECK 330 for (
char*
c = start;
c < (start+lsz);
c++)
337 : cur_hcsz(MemoryConfig::
hcsz_min), requested(0), slack(NULL) {
338 alloc_fill(sm,cur_hcsz,
true);
347 : cur_hcsz(mm.cur_hcsz), requested(0), slack(NULL) {
351 (s_sub*2 < cur_hcsz))
353 alloc_fill(sm,cur_hcsz+s_sub,
true);
369 }
while (hc != NULL);
380 #ifdef GECODE_MEMORY_CHECK 382 char*
c =
static_cast<char*
>(
p);
415 fl_refill<s>(sm); f = fl[
i];
433 l->
next(fl[i]); fl[
i] =
f;
465 (ptr_cast<FreeList*>(NULL));
const size_t hcsz_min
Minimal size of a heap chunk requested from the OS.
void reuse(void *p, size_t s)
Store for reusal, if of sufficient size for free list.
void rfree(void *p)
Free memory block starting at p.
FreeList * next(void) const
Return next freelist object.
void * alloc(SharedMemory &sm, size_t s)
Allocate memory of size s.
void * ralloc(size_t s)
Allocate s bytes from heap.
void fl_dispose(FreeList *f, FreeList *l)
Release all free list elements of size s between f and l (inclusive)
Memory chunk allocated from heap with proper alignment.
FreeList(void)
Use uninitialized.
void free(HeapChunk *hc)
Free heap chunk (or cache for later)
A mutex for mutual exclausion among several threads.
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
Gecode::IntArgs i({1, 2, 3, 4})
const int fl_size_min
Minimal size for free list element.
FreeList ** nextRef(void)
Return pointer to next link in freelist object.
MemoryChunk * next
Next chunk.
unsigned int n_hc
How many heap chunks are available for caching.
HeapChunk * alloc(size_t s, size_t l)
Return heap chunk, preferable of size s, but at least of size l.
FreeList * _next
Pointer to next freelist object.
~SharedMemory(void)
Destructor.
void align(size_t &s, size_t a=GECODE_MEMORY_ALIGNMENT)
Align size s to the required alignment a.
#define GECODE_KERNEL_EXPORT
const int fl_size_max
Maximal size for free list element.
SharedMemory(void)
Initialize.
T ptr_cast(void *p)
Cast p into pointer of type T.
double area[1]
Start of memory area inside chunk.
const int hcsz_dec_ratio
Decrement ratio for chunk size.
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
const size_t hcsz_max
Maximal size of a heap chunk requested from the OS.
const int fl_unit_size
Unit size for free lists.
Heap heap
The single global heap.
Memory chunk with size information.
Base-class for freelist-managed objects.
void * fl_alloc(SharedMemory &sm)
Allocate free list element of size s.
const unsigned int n_hc_cache
How many heap chunks should be cached at most.
size_t size
Size of chunk.
void release(SharedMemory &sm)
Release all allocated heap chunks.
Gecode toplevel namespace
MemoryManager(SharedMemory &sm)
Constructor initialization.
HeapChunk * hc
A list of cached heap chunks.
Shared object for several memory areas.
const int hcsz_inc_ratio
Increment ratio for chunk size.
const int fl_refill
Number of free lists elements to allocate.