ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adpool.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  *
7  * ADModelbuilder and associated libraries and documentations are
8  * provided under the general terms of the "BSD" license.
9  *
10  * License:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * 3. Neither the name of the University of California, Otter Research,
24  * nor the ADMB Foundation nor the names of its contributors may be used
25  * to endorse or promote products derived from this software without
26  * specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
46 #if !defined(__AD_POOL__)
47 #define __AD_POOL__
48 #include <fvar.hpp>
49 
50 //#define __CHECK_MEMORY__
51 
52 #ifdef __CHECK_MEMORY__
53 extern void * pchecker;
54 #endif
55 
59 class adpool
60 {
61  static int num_adpools;
63 
64 public:
65 
66  adpool();
67  adpool(const size_t);
68  adpool(adpool&) = delete;
69  ~adpool();
70 
71  void operator=(adpool&) = delete;
72 
73  static int get_num_adpools()
74  { return adpool::num_adpools; }
75 
76  int depth_check(void);
77  unsigned int nvar;
78  int& on_adpool_vector(void) {return adpool_vector_flag;}
79  char * last_chunk;
80  struct link { link * next; };
83  size_t nelem;
84  size_t size;
86  double* first;
87  void grow(void);
88 
89 #if defined(__CHECK_MEMORY__)
90  int maxchunks;
91  char * minaddress[2000];
92  char * maxaddress[2000];
93  int * pvalues;
94  int nalloc;
95 #endif
96 
97 public:
98  void clean(void);
99  void set_size(const size_t);
100  void* alloc(void);
101  void free(void* b);
102  void deallocate(void);
103 
104 #if defined(__CHECK_MEMORY__)
105  int bad(link * p);
106  int badaddress(link * p);
107  void sanity_check(void);
108  void sanity_check(void *);
109  void sanity_check2(void);
110  void write_pointers(int m,int max);
111 #endif
112 };
113 
114 #endif //defined(__AD_POOL__)
size_t nelem
Definition: adpool.h:83
char * last_chunk
Definition: adpool.h:79
double * first
Definition: adpool.h:86
size_t size
Definition: adpool.h:84
void clean(void)
Description not yet available.
Definition: adpool.cpp:435
~adpool()
Destructor.
Definition: adpool.cpp:255
void operator=(adpool &)=delete
int num_chunks
Definition: adpool.h:82
link * head
Definition: adpool.h:85
void deallocate(void)
Description not yet available.
Definition: adpool.cpp:319
void set_size(const size_t)
Set size of adpool.
Definition: adpool.cpp:304
Description not yet available.
Definition: adpool.h:59
int num_allocated
Definition: adpool.h:81
int depth_check(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: adpool.cpp:19
int adpool_vector_flag
Definition: adpool.h:62
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static int num_adpools
Definition: adpool.h:61
void * alloc(void)
Allocate memory for link*.
Definition: adpool.cpp:114
void * pchecker
void free(void *b)
Description not yet available.
Definition: adpool.cpp:215
static int get_num_adpools()
Definition: adpool.h:73
adpool()
Default constructor.
Definition: adpool.cpp:297
void grow(void)
Definition: adpool.cpp:353
#define max(a, b)
Definition: cbivnorm.cpp:189
int & on_adpool_vector(void)
Definition: adpool.h:78
unsigned int nvar
Definition: adpool.h:77