42 #ifdef GECODE_PEAKHEAP_MALLOC_H
46 #ifdef GECODE_PEAKHEAP_MALLOC_MALLOC_H
47 #include <malloc/malloc.h>
79 T*
alloc(
long unsigned int n);
95 T*
alloc(
unsigned int n);
111 void free(T*
b,
long unsigned int n);
119 void free(T* b,
long int n);
127 void free(T* b,
unsigned int n);
135 void free(T* b,
int n);
148 T*
realloc(T* b,
long unsigned int n,
long unsigned int m);
161 T*
realloc(T* b,
long int n,
long int m);
174 T*
realloc(T* b,
unsigned int n,
unsigned int m);
187 T*
realloc(T* b,
int n,
int m);
196 T**
realloc(T** b,
long unsigned int n,
long unsigned int m);
205 T**
realloc(T** b,
long int n,
long int m);
214 T**
realloc(T** b,
unsigned int n,
unsigned int m);
223 T**
realloc(T** b,
int n,
int m);
233 static T*
copy(T*
d,
const T* s,
long unsigned int n);
243 static T*
copy(T* d,
const T* s,
long int n);
253 static T*
copy(T* d,
const T* s,
unsigned int n);
263 static T*
copy(T* d,
const T* s,
int n);
272 static T**
copy(T** d,
const T** s,
long unsigned int n);
281 static T**
copy(T** d,
const T** s,
long int n);
290 static T**
copy(T** d,
const T** s,
unsigned int n);
299 static T**
copy(T** d,
const T** s,
int n);
308 void rfree(
void* p,
size_t s);
314 static void*
operator new(
size_t s)
throw() { (void) s;
return NULL; }
316 static void operator delete(
void*
p) { (void) p; };
320 const Heap& operator =(
const Heap&) {
return *
this; }
321 #ifdef GECODE_PEAKHEAP
342 void*
p = ::malloc(s);
343 #ifdef GECODE_PEAKHEAP
345 _cur += GECODE_MSIZE(p);
356 #ifdef GECODE_PEAKHEAP
358 _cur -= GECODE_MSIZE(p);
366 #ifdef GECODE_PEAKHEAP
368 _cur -= GECODE_MSIZE(p);
376 #ifdef GECODE_PEAKHEAP
378 _cur -= GECODE_MSIZE(p);
382 #ifdef GECODE_PEAKHEAP
384 _cur += GECODE_MSIZE(p);
388 if (p != NULL || s == 0)
401 T*
p =
static_cast<T*
>(
ralloc(
sizeof(T)*n));
402 for (
long unsigned int i=n;
i--; )
403 (
void)
new (p+
i) T();
410 return alloc<T>(
static_cast<long unsigned int>(
n));
415 return alloc<T>(
static_cast<long unsigned int>(
n));
421 return alloc<T>(
static_cast<long unsigned int>(
n));
427 for (
long unsigned int i=n;
i--; )
435 free<T>(
b,
static_cast<long unsigned int>(
n));
440 free<T>(
b,
static_cast<long unsigned int>(
n));
446 free<T>(
b,
static_cast<long unsigned int>(
n));
454 T*
p =
static_cast<T*
>(
ralloc(
sizeof(T)*m));
455 for (
long unsigned int i=
std::min(n,m);
i--; )
456 (
void)
new (p+
i) T(b[
i]);
457 for (
long unsigned int i=n; i<m; i++)
458 (
void)
new (p+
i) T();
465 assert((n >= 0) && (m >= 0));
466 return realloc<T>(
b,
static_cast<long unsigned int>(
n),
467 static_cast<long unsigned int>(m));
472 return realloc<T>(
b,
static_cast<long unsigned int>(
n),
473 static_cast<long unsigned int>(m));
478 assert((n >= 0) && (m >= 0));
479 return realloc<T>(
b,
static_cast<long unsigned int>(
n),
480 static_cast<long unsigned int>(m));
483 #define GECODE_SUPPORT_REALLOC(T) \
486 Heap::realloc<T>(T* b, long unsigned int, long unsigned int m) { \
487 return static_cast<T*>(rrealloc(b,m*sizeof(T))); \
491 Heap::realloc<T>(T* b, long int n, long int m) { \
492 assert((n >= 0) && (m >= 0)); \
493 return realloc<T>(b,static_cast<long unsigned int>(n), \
494 static_cast<long unsigned int>(m)); \
498 Heap::realloc<T>(T* b, unsigned int n, unsigned int m) { \
499 return realloc<T>(b,static_cast<long unsigned int>(n), \
500 static_cast<long unsigned int>(m)); \
504 Heap::realloc<T>(T* b, int n, int m) { \
505 assert((n >= 0) && (m >= 0)); \
506 return realloc<T>(b,static_cast<long unsigned int>(n), \
507 static_cast<long unsigned int>(m)); \
522 #undef GECODE_SUPPORT_REALLOC
527 return static_cast<T**
>(
rrealloc(b,m*
sizeof(T*)));
532 assert((n >= 0) && (m >= 0));
533 return realloc<T*>(
b,
static_cast<long unsigned int>(
n),
534 static_cast<long unsigned int>(m));
539 return realloc<T*>(
b,
static_cast<long unsigned int>(
n),
540 static_cast<long unsigned int>(m));
545 assert((n >= 0) && (m >= 0));
546 return realloc<T*>(
b,
static_cast<long unsigned int>(
n),
547 static_cast<long unsigned int>(m));
553 for (
long unsigned int i=n;
i--; )
561 return copy<T>(
d,s,
static_cast<long unsigned int>(
n));
566 return copy<T>(
d,s,
static_cast<long unsigned int>(
n));
572 return copy<T>(
d,s,
static_cast<long unsigned int>(
n));
575 #define GECODE_SUPPORT_COPY(T) \
578 Heap::copy(T* d, const T* s, long unsigned int n) { \
579 return static_cast<T*>(memcpy(d,s,n*sizeof(T))); \
583 Heap::copy(T* d, const T* s, long int n) { \
585 return copy<T>(d,s,static_cast<long unsigned int>(n)); \
589 Heap::copy(T* d, const T* s, unsigned int n) { \
590 return copy<T>(d,s,static_cast<long unsigned int>(n)); \
594 Heap::copy(T* d, const T* s, int n) { \
596 return copy<T>(d,s,static_cast<long unsigned int>(n)); \
611 #undef GECODE_SUPPORT_COPY
616 return static_cast<T**
>(memcpy(d,s,n*
sizeof(T*)));
622 return copy<T*>(
d,s,
static_cast<long unsigned int>(
n));
627 return copy<T*>(
d,s,
static_cast<long unsigned int>(
n));
633 return copy<T*>(
d,s,
static_cast<long unsigned int>(
n));
636 #ifdef GECODE_PEAKHEAP
static T * copy(T *d, const T *s, long unsigned int n)
Copy n objects starting at s to d.
#define GECODE_SUPPORT_REALLOC(T)
const FloatNum max
Largest allowed float value.
void rfree(void *p)
Free memory block starting at p.
void * ralloc(size_t s)
Allocate s bytes from heap.
Exception: Memory exhausted
Heap(void)
Default constructor (ensuring that only a single instance is created)
Heap heap
The single global heap.
A mutex for mutual exclausion among several threads.
int p
Number of positive literals for node type.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
const FloatNum min
Smallest allowed float value.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
#define GECODE_SUPPORT_EXPORT
Heap memory management class
#define GECODE_SUPPORT_COPY(T)
void * rrealloc(void *p, size_t s)
Change memory block starting at p to size s.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
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.
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace