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
344 static void*
operator new(
size_t s);
347 static void operator delete(
void*
p);
359 #ifdef GECODE_PEAKHEAP
361 _cur += GECODE_MSIZE(
p);
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);
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));
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));
497 return realloc<T>(
b,static_cast<long unsigned int>(
n),
498 static_cast<long unsigned int>(m));
503 return realloc<T>(
b,static_cast<long unsigned int>(
n),
504 static_cast<long unsigned int>(m));
509 assert((
n >= 0) && (m >= 0));
510 return realloc<T>(
b,static_cast<long unsigned int>(
n),
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));
564 return realloc<T*>(
b,static_cast<long unsigned int>(
n),
565 static_cast<long unsigned int>(m));
570 return realloc<T*>(
b,static_cast<long unsigned int>(
n),
571 static_cast<long unsigned int>(m));
576 assert((
n >= 0) && (m >= 0));
577 return realloc<T*>(
b,static_cast<long unsigned int>(
n),
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