38#ifdef GECODE_PEAKHEAP_MALLOC_H
42#ifdef GECODE_PEAKHEAP_MALLOC_MALLOC_H
43#include <malloc/malloc.h>
75 T*
alloc(
long unsigned int n);
107 void free(T*
b,
long unsigned int n);
115 void free(T*
b,
long int n);
123 void free(T*
b,
unsigned int n);
144 T*
realloc(T*
b,
long unsigned int n,
long unsigned int m);
157 T*
realloc(T*
b,
long int n,
long int m);
170 T*
realloc(T*
b,
unsigned int n,
unsigned int m);
192 T**
realloc(T**
b,
long unsigned int n,
long unsigned int m);
201 T**
realloc(T**
b,
long int n,
long int m);
210 T**
realloc(T**
b,
unsigned int n,
unsigned int m);
229 static T*
copy(T* d,
const T* s,
long unsigned int n);
239 static T*
copy(T* d,
const T* s,
long int n);
249 static T*
copy(T* d,
const T* s,
unsigned int n);
259 static T*
copy(T* d,
const T* s,
int n);
268 static T**
copy(T** d,
const T** s,
long unsigned int n);
277 static T**
copy(T** d,
const T** s,
long int n);
286 static T**
copy(T** d,
const T** s,
unsigned int n);
295 static T**
copy(T** d,
const T** s,
int n);
304 void rfree(
void*
p,
size_t s);
310 static void*
operator new(
size_t s)
throw() { (void) s;
return NULL; }
312 static void operator delete(
void*
p) { (void)
p; };
316 const Heap& operator =(
const Heap&) {
return *
this; }
317#ifdef GECODE_PEAKHEAP
345 static void*
operator new(
size_t s);
347 static void operator delete(
void*
p);
359#ifdef GECODE_PEAKHEAP
361 _cur += GECODE_MSIZE(
p);
362 _peak = std::max(_peak,_cur);
372#ifdef GECODE_PEAKHEAP
374 _cur -= GECODE_MSIZE(
p);
382#ifdef GECODE_PEAKHEAP
384 _cur -= GECODE_MSIZE(
p);
392#ifdef GECODE_PEAKHEAP
394 _cur -= GECODE_MSIZE(
p);
398#ifdef GECODE_PEAKHEAP
400 _cur += GECODE_MSIZE(
p);
401 _peak = std::max(_peak,_cur);
404 if (
p != NULL || s == 0)
415 HeapAllocated::operator
new(
size_t s) {
419 HeapAllocated::operator
delete(
void*
p) {
432 T*
p =
static_cast<T*
>(
ralloc(
sizeof(T)*
n));
433 for (
long unsigned int i=0U; i<
n; i++)
434 (
void)
new (
p+i) T();
441 return alloc<T>(
static_cast<long unsigned int>(
n));
446 return alloc<T>(
static_cast<long unsigned int>(
n));
452 return alloc<T>(
static_cast<long unsigned int>(
n));
458 for (
long unsigned int i=0U; i<
n; i++)
466 free<T>(
b,
static_cast<long unsigned int>(
n));
471 free<T>(
b,
static_cast<long unsigned int>(
n));
477 free<T>(
b,
static_cast<long unsigned int>(
n));
485 T*
p =
static_cast<T*
>(
ralloc(
sizeof(T)*m));
486 for (
long unsigned int i=0U; i<std::min(
n,m); i++)
487 (
void)
new (
p+i) T(
b[i]);
488 for (
long unsigned int i=
n; i<m; i++)
489 (
void)
new (
p+i) T();
496 assert((
n >= 0) && (m >= 0));
498 static_cast<long unsigned int>(m));
504 static_cast<long unsigned int>(m));
509 assert((
n >= 0) && (m >= 0));
511 static_cast<long unsigned int>(m));
514#define GECODE_SUPPORT_REALLOC(T) \
517 Heap::realloc<T>(T* b, long unsigned int, long unsigned int m) { \
518 return static_cast<T*>(rrealloc(b,m*sizeof(T))); \
522 Heap::realloc<T>(T* b, long int n, long int m) { \
523 assert((n >= 0) && (m >= 0)); \
524 return realloc<T>(b,static_cast<long unsigned int>(n), \
525 static_cast<long unsigned int>(m)); \
529 Heap::realloc<T>(T* b, unsigned int n, unsigned int m) { \
530 return realloc<T>(b,static_cast<long unsigned int>(n), \
531 static_cast<long unsigned int>(m)); \
535 Heap::realloc<T>(T* b, int n, int m) { \
536 assert((n >= 0) && (m >= 0)); \
537 return realloc<T>(b,static_cast<long unsigned int>(n), \
538 static_cast<long unsigned int>(m)); \
553#undef GECODE_SUPPORT_REALLOC
558 return static_cast<T**
>(
rrealloc(
b,m*
sizeof(T*)));
563 assert((
n >= 0) && (m >= 0));
565 static_cast<long unsigned int>(m));
571 static_cast<long unsigned int>(m));
576 assert((
n >= 0) && (m >= 0));
578 static_cast<long unsigned int>(m));
584 for (
long unsigned int i=0U; i<
n; i++)
592 return copy<T>(d,s,
static_cast<long unsigned int>(
n));
597 return copy<T>(d,s,
static_cast<long unsigned int>(
n));
603 return copy<T>(d,s,
static_cast<long unsigned int>(
n));
606#define GECODE_SUPPORT_COPY(T) \
609 Heap::copy(T* d, const T* s, long unsigned int n) { \
610 return static_cast<T*>(Support::allocator.memcpy(d,s,n*sizeof(T))); \
614 Heap::copy(T* d, const T* s, long int n) { \
616 return copy<T>(d,s,static_cast<long unsigned int>(n)); \
620 Heap::copy(T* d, const T* s, unsigned int n) { \
621 return copy<T>(d,s,static_cast<long unsigned int>(n)); \
625 Heap::copy(T* d, const T* s, int n) { \
627 return copy<T>(d,s,static_cast<long unsigned int>(n)); \
642#undef GECODE_SUPPORT_COPY
653 return copy<T*>(d,s,
static_cast<long unsigned int>(
n));
658 return copy<T*>(d,s,
static_cast<long unsigned int>(
n));
664 return copy<T*>(d,s,
static_cast<long unsigned int>(
n));
667#ifdef GECODE_PEAKHEAP
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
Base class for heap allocated objects.
Heap memory management class
Heap(void)
Default constructor (ensuring that only a single instance is created)
void * rrealloc(void *p, size_t s)
Change memory block starting at p to size s.
T * realloc(T *b, long unsigned int n, long unsigned int m)
Reallocate block of n objects starting at b to m objects of type T from heap.
static T * copy(T *d, const T *s, long unsigned int n)
Copy n objects starting at s to d.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
void rfree(void *p)
Free memory block starting at p.
void * ralloc(size_t s)
Allocate s bytes from heap.
Exception: Memory exhausted
void free(void *p)
Free memory block p.
void * memcpy(void *d, const void *s, size_t n)
Copy n bytes from source s directly to d and returns d.
void * alloc(size_t n)
Allocate memory block of size n.
void * realloc(void *p, size_t n)
Return address of reallocated memory block p of size n.
A mutex for mutual exclausion among several threads.
Heap heap
The single global heap.
Allocator allocator
The single global default memory allocator.
#define GECODE_SUPPORT_REALLOC(T)
#define GECODE_SUPPORT_COPY(T)
Gecode toplevel namespace
#define GECODE_SUPPORT_EXPORT