41namespace Gecode {
namespace Kernel {
117namespace Gecode {
namespace Kernel {
141 void alloc_fill(
SharedMemory& sm,
size_t s,
bool first);
155 static size_t sz2i(
size_t);
157 static size_t i2sz(
size_t);
171 void reuse(
void*
p,
size_t s);
176namespace Gecode {
namespace Kernel {
190 while (heap.hc != NULL) {
201 while ((heap.hc != NULL) && (heap.hc->size <
l)) {
208 if (heap.hc == NULL) {
209 assert(heap.n_hc == 0);
264namespace Gecode {
namespace Kernel {
272 MemoryManager::sz2i(
size_t s) {
279 MemoryManager::i2sz(
size_t i) {
298 return &cur_hc->
area[0];
302 MemoryManager::alloc_fill(
SharedMemory& sm,
size_t sz,
bool first) {
311 size_t overhead =
sizeof(HeapChunk) -
sizeof(
double);
314 size_t allocate = ((sz > cur_hcsz) ?
315 (((size_t) (sz / cur_hcsz)) + 1) * cur_hcsz : cur_hcsz);
317 HeapChunk* hc = sm.
alloc(allocate,sz);
319 lsz = hc->size - overhead;
322 requested = hc->size;
323 hc->next = NULL; cur_hc = hc;
325 requested += hc->size;
326 hc->next = cur_hc->
next; cur_hc->
next = hc;
328#ifdef GECODE_MEMORY_CHECK
329 for (
char* c = start;
c < (start+lsz);
c++)
336 : cur_hcsz(MemoryConfig::hcsz_min), requested(0), slack(NULL) {
337 alloc_fill(sm,cur_hcsz,
true);
346 : cur_hcsz(mm.cur_hcsz), requested(0), slack(NULL) {
350 (s_sub*2 < cur_hcsz))
352 alloc_fill(sm,cur_hcsz+s_sub,
true);
368 }
while (hc != NULL);
379#ifdef GECODE_MEMORY_CHECK
381 char* c =
static_cast<char*
>(
p);
398 f->
next(fl[i]); fl[i]=f;
414 fl_refill<s>(sm); f = fl[i];
432 l->
next(fl[i]); fl[i] = f;
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
Base-class for freelist-managed objects.
FreeList ** nextRef(void)
Return pointer to next link in freelist object.
FreeList(void)
Use uninitialized.
FreeList * next(void) const
Return next freelist object.
FreeList * _next
Pointer to next freelist object.
void rfree(void *p)
Free memory block starting at p.
void * ralloc(size_t s)
Allocate s bytes from heap.
Memory chunk allocated from heap with proper alignment.
double area[1]
Start of memory area inside chunk.
Memory chunk with size information.
size_t size
Size of chunk.
MemoryChunk * next
Next chunk.
void * fl_alloc(SharedMemory &sm)
Allocate free list element of size s.
void release(SharedMemory &sm)
Release all allocated heap chunks.
void reuse(void *p, size_t s)
Store for reusal, if of sufficient size for free list.
void * alloc(SharedMemory &sm, size_t s)
Allocate memory of size s.
MemoryManager(SharedMemory &sm)
Constructor initialization.
void fl_dispose(FreeList *f, FreeList *l)
Release all free list elements of size s between f and l (inclusive)
void * subscriptions(void) const
Get the memory area for subscriptions.
Shared object for several memory areas.
SharedMemory(void)
Initialize.
HeapChunk * alloc(size_t s, size_t l)
Return heap chunk, preferable of size s, but at least of size l.
HeapChunk * hc
A list of cached heap chunks.
void free(HeapChunk *hc)
Free heap chunk (or cache for later)
unsigned int n_hc
How many heap chunks are available for caching.
~SharedMemory(void)
Destructor.
A lock as a scoped frontend for a mutex.
A mutex for mutual exclausion among several threads.
Base * next(void) const
Return next test.
Heap heap
The single global heap.
#define GECODE_KERNEL_EXPORT
const int hcsz_inc_ratio
Increment ratio for chunk size.
const size_t hcsz_max
Maximal size of a heap chunk requested from the OS.
const int fl_size_max
Maximal size for free list element.
void align(size_t &s, size_t a=GECODE_MEMORY_ALIGNMENT)
Align size s to the required alignment a.
const int fl_unit_size
Unit size for free lists.
const unsigned int n_hc_cache
How many heap chunks should be cached at most.
const size_t hcsz_min
Minimal size of a heap chunk requested from the OS.
const int fl_refill
Number of free lists elements to allocate.
const int fl_size_min
Minimal size for free list element.
const int hcsz_dec_ratio
Decrement ratio for chunk size.
Gecode toplevel namespace
T ptr_cast(void *p)
Cast p into pointer of type T.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})