45 namespace Gecode {
namespace Kernel {
121 namespace Gecode {
namespace Kernel {
145 void alloc_fill(
SharedMemory& sm,
size_t s,
bool first);
151 void* subscriptions(
void)
const;
159 static size_t sz2i(
size_t);
161 static size_t i2sz(
size_t);
175 void reuse(
void*
p,
size_t s);
180 namespace Gecode {
namespace Kernel {
194 while (
heap.hc != NULL) {
204 while ((
heap.hc != NULL) && (
heap.hc->size < l)) {
211 if (
heap.hc == NULL) {
212 assert(
heap.n_hc == 0);
269 namespace Gecode {
namespace Kernel {
277 MemoryManager::sz2i(
size_t s) {
284 MemoryManager::i2sz(
size_t i) {
302 MemoryManager::subscriptions(
void)
const {
303 return &cur_hc->area[0];
307 MemoryManager::alloc_fill(
SharedMemory& sm,
size_t sz,
bool first) {
316 size_t overhead =
sizeof(
HeapChunk) -
sizeof(
double);
319 size_t allocate = ((sz > cur_hcsz) ?
320 (((
size_t) (sz / cur_hcsz)) + 1) * cur_hcsz : cur_hcsz);
324 lsz = hc->
size - overhead;
327 requested = hc->
size;
328 hc->
next = NULL; cur_hc = hc;
330 requested += hc->
size;
333 #ifdef GECODE_MEMORY_CHECK 334 for (
char*
c = start;
c < (start+lsz);
c++)
341 : cur_hcsz(MemoryConfig::
hcsz_min), requested(0), slack(NULL) {
342 alloc_fill(sm,cur_hcsz,
true);
351 : cur_hcsz(mm.cur_hcsz), requested(0), slack(NULL) {
355 (s_sub*2 < cur_hcsz))
357 alloc_fill(sm,cur_hcsz+s_sub,
true);
373 }
while (hc != NULL);
384 #ifdef GECODE_MEMORY_CHECK 386 char*
c =
static_cast<char*
>(
p);
419 fl_refill<s>(sm); f = fl[
i];
437 l->
next(fl[i]); fl[
i] =
f;
469 (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 align(size_t &s)
Align size s to the required alignment.
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.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
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.
#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.