00001 /*!@file Envision/env_alloc.h memory allocation routines for 16-byte alignment */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Envision/env_alloc.h $ 00035 // $Id: env_alloc.h 8338 2007-05-04 00:59:03Z rjpeters $ 00036 // 00037 00038 #ifndef ENVISION_ENV_ALLOC_H_DEFINED 00039 #define ENVISION_ENV_ALLOC_H_DEFINED 00040 00041 #include "Envision/env_types.h" 00042 00043 #define ENV_NCACHE ((env_size_t)32) 00044 00045 struct env_alloc_stats 00046 { 00047 env_size_t nalign; 00048 env_size_t ncache_used; 00049 unsigned long long nbytes_alltime; 00050 env_size_t nallocations_alltime; 00051 env_size_t nbytes_current; 00052 env_size_t nallocations_current; 00053 env_size_t bytes_allocated; 00054 env_size_t overhead; 00055 00056 struct 00057 { 00058 env_size_t num_allocations; 00059 env_size_t alloc_size; 00060 env_size_t num_active; 00061 } cache[ENV_NCACHE]; 00062 }; 00063 00064 #ifdef __cplusplus 00065 extern "C" 00066 { 00067 #endif 00068 00069 typedef void* (env_alloc_func)(env_size_t); 00070 typedef void (env_dealloc_func)(void*); 00071 00072 /// Allocate nbytes of memory, throwing an exception in case of failure. 00073 void* env_allocate(env_size_t nbytes); 00074 00075 /// Deallocate the given memory region. 00076 void env_deallocate(void* mem); 00077 00078 /// Get current memory allocator stats 00079 void env_allocation_get_stats(struct env_alloc_stats* stats); 00080 00081 /// Initialize memory allocator 00082 /** @param alloc_func pointer to some function that allocates 00083 raw memory (e.g. something that wraps malloc()) 00084 00085 @param dealloc_func pointer to some function that 00086 deallocates raw memory (e.g. free()) 00087 */ 00088 void env_allocation_init(env_alloc_func* alloc_func, 00089 env_dealloc_func* dealloc_func); 00090 00091 /// Release any cached memory blocks 00092 void env_allocation_cleanup(void); 00093 00094 typedef void (env_alloc_mutex_func)(void*); 00095 00096 /// Install callbacks to provide thread-safety if desired 00097 /** @param mutex_acquire this function will be called at the 00098 beginning of every env_allocate(), env_deallocate(), 00099 env_allocation_get_stats(), env_allocation_init(), and 00100 env_allocation_cleanup() call 00101 00102 @param mutex_release this function will be called at the 00103 end of every such call 00104 00105 It is not necessary to install any callbacks in a program 00106 where env_allocate() and env_deallocate() are always 00107 called from just a single thread; but any program that 00108 might use those functions concurrently from multiple 00109 threads must install mutex functions here. */ 00110 void env_allocation_init_mutex_funcs(void* userdata, 00111 env_alloc_mutex_func* mutex_acquire, 00112 env_alloc_mutex_func* mutex_release); 00113 00114 #ifdef __cplusplus 00115 } 00116 #endif 00117 00118 // ###################################################################### 00119 /* So things look consistent in everyone's emacs... */ 00120 /* Local Variables: */ 00121 /* c-file-style: "linux" */ 00122 /* indent-tabs-mode: nil */ 00123 /* End: */ 00124 00125 #endif // ENVISION_ENV_ALLOC_H_DEFINED