ADMB Documentation  11.1.2403
 All Classes Files Functions Variables Typedefs Friends Defines
dfpool.h
Go to the documentation of this file.
00001 /*
00002  * $Id: dfpool.h 1919 2014-04-22 22:02:01Z 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  */
00045 #if !defined(__DF_POOL__)
00046 #define  __DF_POOL__
00047 #include <fvar.hpp>
00048 extern void * pchecker;
00049 //#define __CHECK_MEMORY__
00050 class link;
00051 
00056 class dfpool
00057 {
00058   int dfpool_vector_flag;
00059 public:
00060   int nvar;
00061   int& on_dfpool_vector(void) {return dfpool_vector_flag;}
00062   char * last_chunk;
00063   struct link { link * next; };
00064   int num_allocated;
00065   int num_chunks;
00066   int nelem;
00067   unsigned size;
00068   link * head;
00069   double * first;
00070   dfpool(dfpool&);  // copy protection
00071   void operator = (dfpool&); // copy protection
00072   void grow(void);
00073 #if defined(__CHECK_MEMORY__)
00074   int maxchunks;
00075   char * minaddress[100];
00076   char * maxaddress[100];
00077   int * pvalues;
00078   int nalloc;
00079 #endif
00080 public:
00081   void clean(void);
00082   dfpool(unsigned);
00083   void set_size(unsigned);
00084   dfpool(void);
00085  ~dfpool();
00086   void * alloc(void);
00087   void free(void * b);
00088   void deallocate(void);
00089 #if defined(__CHECK_MEMORY__)
00090   int bad(link * p);
00091   int badaddress(link * p);
00092   void sanity_check(void);
00093   void sanity_check(void *);
00094   void sanity_check2(void);
00095   void write_pointers(int m,int max);
00096 #endif
00097 };
00098 
00103 class tsdfpool : public dfpool
00104 {
00105 public:
00106   tsdfpool(int n);
00107   void * alloc(void);
00108   void free(void * b);
00109 };
00110 
00111 #endif //defined(__DF_POOL__)