ADMB Documentation  11.1.2545
 All Classes Files Functions Variables Typedefs Friends Defines
adpool.h
Go to the documentation of this file.
00001 /*
00002  * $Id: adpool.h 2539 2014-10-31 19:54:20Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00046 #if !defined(__AD_POOL__)
00047 #define  __AD_POOL__
00048 #include <fvar.hpp>
00049 extern void * pchecker;
00050 //#define __CHECK_MEMORY__
00051 
00055 class adpool
00056 {
00057   static int num_adpools;
00058   int adpool_vector_flag;
00059 public:
00060   adpool();
00061   adpool(const size_t);
00062  ~adpool();
00063 
00064   int depth_check(void);
00065   int nvar;
00066   int& on_adpool_vector(void) {return adpool_vector_flag;}
00067   char * last_chunk;
00068   struct link { link * next; };
00069   int num_allocated;
00070   int num_chunks;
00071   size_t nelem;
00072   size_t size;
00073   link* head;
00074   double* first;
00075   adpool(adpool&);  // copy protection
00076   void operator=(adpool&); // copy protection
00077   void grow(void);
00078 #if defined(__CHECK_MEMORY__)
00079   int maxchunks;
00080   char * minaddress[2000];
00081   char * maxaddress[2000];
00082   int * pvalues;
00083   int nalloc;
00084 #endif
00085 public:
00086   void clean(void);
00087   void set_size(const size_t);
00088   void* alloc(void);
00089   void free(void* b);
00090   void deallocate(void);
00091 #if defined(__CHECK_MEMORY__)
00092   int bad(link * p);
00093   int badaddress(link * p);
00094   void sanity_check(void);
00095   void sanity_check(void *);
00096   void sanity_check2(void);
00097   void write_pointers(int m,int max);
00098 #endif
00099 };
00100 
00101 #endif //defined(__AD_POOL__)