109 static void*
operator new(
size_t s);
111 static void operator delete(
void*
p);
162 void alloc_fill(
SharedMemory* sm,
size_t s,
bool first);
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);
277 hc->
next = heap.hc; heap.hc =
hc;
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);
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;
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));
507 (ptr_cast<FreeList*>(NULL));
Memory chunk with size information.
void * subscriptions(void) const
Get the memory area for subscriptions.
const int fl_size_max
Maximal size for free list element.
MemoryManager(SharedMemory *sm)
Constructor initialization.
SharedMemory(void)
Initialize.
const unsigned int n_hc_cache
How many heap chunks should be cached at most.
const int hcsz_inc_ratio
Increment ratio for chunk size.
void rfree(void *p)
Free memory block starting at p.
void fl_dispose(FreeList *f, FreeList *l)
Release all free list elements of size s between f and l (inclusive)
void * fl_alloc(SharedMemory *sm)
Allocate free list element of size s.
const size_t hcsz_min
Minimal size of a heap chunk requested from the OS.
HeapChunk * heap_alloc(size_t s, size_t l)
Return heap chunk, preferable of size s, but at least of size l.
bool region_alloc(size_t s, void *&p)
Return memory chunk if available.
void * ralloc(size_t s)
Allocate s bytes from heap.
FreeList * next(void) const
Return next freelist object.
SharedMemory * copy(bool share)
Return copy during cloning.
const size_t hcsz_max
Maximal size of a heap chunk requested from the OS.
Memory chunk allocated from heap with proper alignment.
void reuse(void *p, size_t s)
Store for reusal, if of sufficient size for free list.
const int hcsz_dec_ratio
Decrement ratio for chunk size.
FreeList(void)
Use uninitialized.
Heap heap
The single global heap.
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
void release(SharedMemory *sm)
Release all allocated heap chunks.
const int fl_refill
Number of free lists elements to allocate.
FreeList ** nextRef(void)
Return pointer to next link in freelist object.
FreeList * _next
Pointer to next freelist object.
#define GECODE_KERNEL_EXPORT
void * alloc(SharedMemory *sm, size_t s)
Allocate memory of size s.
~SharedMemory(void)
Destructor.
T ptr_cast(void *p)
Cast p into pointer of type T.
const int fl_size_min
Minimal size for free list element.
double area[1]
Start of memory area inside chunk.
size_t size
Size of chunk.
const size_t region_area_size
Size of region area.
Base-class for freelist-managed objects.
unsigned int n_hc
How many heap chunks are available for caching.
void heap_free(HeapChunk *hc)
Free heap chunk (or cache for later)
const int fl_unit_size
Unit size for free lists.
HeapChunk * hc
A list of cached heap chunks.
double area[MemoryConfig::region_area_size/sizeof(double)]
The actual memory area (allocated from top to bottom)
Gecode toplevel namespace
size_t free
Amount of free memory.
MemoryChunk * next
Next chunk.
void align(size_t &s)
Align size s to the required alignment.
Shared object for several memory areas.
void flush(void)
Flush all cached memory.
bool release(void)
Release by one space.