fei_Pool_alloc.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include "fei_macros.hpp"
00010 
00011 #include "fei_Pool_alloc.hpp"
00012 #include "fei_Pool.hpp"
00013 
00014 #include <cstdlib>
00015 #include <map>
00016 
00017 struct fei_map_holder {
00018   std::map<size_t,fei_Pool*> fei_mem_pools;
00019 
00020   ~fei_map_holder()
00021   {
00022     std::map<size_t,fei_Pool*>::iterator
00023       iter = fei_mem_pools.begin(),
00024       iter_end = fei_mem_pools.end();
00025     for(; iter != iter_end; ++iter) {
00026       delete iter->second;
00027     }
00028   }
00029 };
00030 
00031 static fei_map_holder fmh;
00032 
00033 fei_Pool* get_fei_mem_pool(size_t n)
00034 {
00035   std::map<size_t,fei_Pool*>::iterator
00036     iter = fmh.fei_mem_pools.find(n);
00037 
00038   if (iter == fmh.fei_mem_pools.end()) {
00039     fei_Pool* new_pool = new fei_Pool(n);
00040     fmh.fei_mem_pools.insert(std::make_pair(n,new_pool));
00041     return(new_pool);
00042   }
00043 
00044   return(iter->second);
00045 }
00046 

Generated on Tue Jul 13 09:27:45 2010 for FEI by  doxygen 1.4.7