Go to the documentation of this file.
109 static void*
operator new(
size_t s);
111 static void operator delete(
void*
p);
176 static size_t sz2i(
size_t);
178 static size_t i2sz(
size_t);
192 void reuse(
void*
p,
size_t s);
202 SharedMemory::operator
new(
size_t s) {
206 SharedMemory::operator
delete(
void*
p) {
219 while (heap.hc != NULL) {
240 return --use_cnt == 0;
248 p = ptr_cast<char*>(®ion.area[0]) + region.free;
253 while ((heap.hc != NULL) && (heap.hc->size <
l)) {
259 if (heap.hc == NULL) {
260 assert(heap.n_hc == 0);
310 MemoryManager::sz2i(
size_t s) {
317 MemoryManager::i2sz(
size_t i) {
341 return &cur_hc->
area[0];
345 MemoryManager::alloc_fill(
SharedMemory*
sm,
size_t sz,
bool first) {
354 size_t overhead =
sizeof(HeapChunk) -
sizeof(
double);
357 size_t allocate = ((sz > cur_hcsz) ?
358 (((
size_t) (sz / cur_hcsz)) + 1) * cur_hcsz : cur_hcsz);
360 HeapChunk* hc =
sm->heap_alloc(allocate,sz);
361 start = ptr_cast<char*>(&hc->area[0]);
362 lsz = hc->size - overhead;
365 requested = hc->size;
366 hc->next = NULL; cur_hc = hc;
368 requested += hc->size;
369 hc->next = cur_hc->
next; cur_hc->
next = hc;
371 #ifdef GECODE_MEMORY_CHECK
372 for (
char*
c = start;
c < (start+lsz);
c++)
379 : cur_hcsz(MemoryConfig::
hcsz_min), requested(0), slack(NULL) {
380 alloc_fill(
sm,cur_hcsz,
true);
389 : cur_hcsz(mm.cur_hcsz), requested(0), slack(NULL) {
393 (s_sub*2 < cur_hcsz))
395 alloc_fill(
sm,cur_hcsz+s_sub,
true);
411 }
while (hc != NULL);
422 #ifdef GECODE_MEMORY_CHECK
424 char*
c =
static_cast<char*
>(
p);
441 f->next(fl[
i]); fl[
i]=
f;
457 fl_refill<s>(
sm);
f = fl[
i];
475 l->next(fl[
i]); fl[
i] =
f;
486 char* block = ptr_cast<char*>(m);
490 fl[sz2i(sz)] = ptr_cast<FreeList*>(block);
492 ptr_cast<FreeList*>(block)->next(ptr_cast<FreeList*>(block+sz));
496 ptr_cast<FreeList*>(block)->next(NULL);
500 fl[sz2i(sz)] = ptr_cast<FreeList*>(block);
503 ptr_cast<FreeList*>(block+
i*sz)->next(ptr_cast<FreeList*>(block+(
i+1)*sz));
505 ptr_cast<FreeList*>(block+
507 (ptr_cast<FreeList*>(NULL));
FreeList ** nextRef(void)
Return pointer to next link in freelist object.
FreeList * _next
Pointer to next freelist object.
const unsigned int n_hc_cache
How many heap chunks should be cached at most.
size_t size
Size of chunk.
void heap_free(HeapChunk *hc)
Free heap chunk (or cache for later)
const int hcsz_inc_ratio
Increment ratio for chunk size.
const int fl_size_max
Maximal size for free list element.
void fl_dispose(FreeList *f, FreeList *l)
Release all free list elements of size s between f and l (inclusive)
MemoryManager(SharedMemory *sm)
Constructor initialization.
MemoryChunk * next
Next chunk.
const int fl_unit_size
Unit size for free lists.
HeapChunk * hc
A list of cached heap chunks.
Gecode::IntArgs i(4, 1, 2, 3, 4)
void * ralloc(size_t s)
Allocate s bytes from heap.
const int hcsz_dec_ratio
Decrement ratio for chunk size.
size_t free
Amount of free memory.
const size_t hcsz_max
Maximal size of a heap chunk requested from the OS.
Memory chunk with size information.
~SharedMemory(void)
Destructor.
Gecode toplevel namespace
double area[1]
Start of memory area inside chunk.
void release(SharedMemory *sm)
Release all allocated heap chunks.
void * fl_alloc(SharedMemory *sm)
Allocate free list element of size s.
FreeList * next(void) const
Return next freelist object.
bool region_alloc(size_t s, void *&p)
Return memory chunk if available.
SharedMemory * copy(bool share)
Return copy during cloning.
unsigned int n_hc
How many heap chunks are available for caching.
HeapChunk * heap_alloc(size_t s, size_t l)
Return heap chunk, preferable of size s, but at least of size l.
void * alloc(SharedMemory *sm, size_t s)
Allocate memory of size s.
Memory chunk allocated from heap with proper alignment.
double area[MemoryConfig::region_area_size/sizeof(double)]
The actual memory area (allocated from top to bottom)
const int fl_refill
Number of free lists elements to allocate.
#define GECODE_KERNEL_EXPORT
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.
Heap heap
The single global heap.
Base-class for freelist-managed objects.
Base * next(void) const
Return next test.
void flush(void)
Flush all cached memory.
void * subscriptions(void) const
Get the memory area for subscriptions.
bool release(void)
Release by one space.
IntPropLevel sm(IntPropLevel ipl)
Extract speed or memory from propagation level.
FreeList(void)
Use uninitialized.
SharedMemory(void)
Initialize.
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
const int fl_size_min
Minimal size for free list element.
Gecode::FloatVal c(-8, 8)
Shared object for several memory areas.
int n
Number of negative literals for node type.
void align(size_t &s)
Align size s to the required alignment.
void rfree(void *p)
Free memory block starting at p.
int p
Number of positive literals for node type.
const size_t region_area_size
Size of region area.