Generated on Thu Jan 31 2019 20:56:41 for Gecode by doxygen 1.8.15
allocator.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2016
8  *
9  * Last modified:
10  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11  * $Revision: 14967 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <cstring>
39 #include <cstdlib>
40 
41 #ifdef GECODE_PEAKHEAP_MALLOC_H
42 #include <malloc.h>
43 #endif
44 
45 #ifdef GECODE_PEAKHEAP_MALLOC_MALLOC_H
46 #include <malloc/malloc.h>
47 #endif
48 
49 #ifdef GECODE_ALLOCATOR
50 
51 namespace Gecode { namespace Support {
52 
64  class Allocator {
65  public:
67  Allocator(void);
69  void* alloc(size_t n);
71  void* realloc(void* p, size_t n);
73  void free(void* p);
75  void* memcpy(void *d, const void *s, size_t n);
76  };
77 
78 
81  }
82  forceinline void*
83  Allocator::alloc(size_t n) {
84  return ::malloc(n);
85  }
86  forceinline void*
87  Allocator::realloc(void* p, size_t n) {
88  return ::realloc(p,n);
89  }
90  forceinline void
91  Allocator::free(void* p) {
92  ::free(p);
93  }
94  forceinline void*
95  Allocator::memcpy(void *d, const void *s, size_t n) {
96  return ::memcpy(d,s,n);
97  }
98 
99 }}
100 
101 #endif
102 
103 namespace Gecode { namespace Support {
104 
109  extern GECODE_SUPPORT_EXPORT
110  Allocator allocator;
111 
112 }}
113 
114 // STATISTICS: support-any
void * realloc(void *p, size_t n)
Return address of reallocated memory block p of size n.
Definition: allocator.hpp:87
Gecode::IntSet d(v, 7)
Default memory allocator.
Definition: allocator.hpp:64
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
void * memcpy(void *d, const void *s, size_t n)
Copy n bytes from source s directly to d and returns d.
Definition: allocator.hpp:95
#define GECODE_SUPPORT_EXPORT
Definition: support.hh:75
Allocator allocator
The single global default memory allocator.
Definition: allocator.cpp:42
#define forceinline
Definition: config.hpp:173
Allocator(void)
Default constructor.
Definition: allocator.hpp:80
Gecode toplevel namespace
void * alloc(size_t n)
Allocate memory block of size n.
Definition: allocator.hpp:83
void free(void *p)
Free memory block p.
Definition: allocator.hpp:91