Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/salloc.h

Go to the documentation of this file.
00001 /*
00002  * lib/salloc.h
00003  * 
00004  * Standard memory (de)allocation routines. 
00005  * 
00006  * Copyright (c) 2000--2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #ifndef _SRC_SALLOC_H_
00018 #define _SRC_SALLOC_H_ 1
00019 
00028 #include <lib/sconfig.h>    /* MUST be first */
00029 
00033 struct LMallocUsage
00034 {
00035     size_t alloc_limit;    
00036     size_t curr_used;      
00037     size_t max_used;       
00038     size_t malloc_calls;   
00039     size_t realloc_calls;  
00040     size_t free_calls;     
00041     int used_chunks;       
00042     int max_used_chunks;   
00043     int real_failures;     
00044     int limit_failures;    
00045 };
00046 
00047 
00049 void LMallocGetUsage(struct LMallocUsage *dest);
00050 
00052 void LMallocSetLimit(size_t limit);
00053 
00054 
00061 extern void _AllocFailure(size_t size);
00062 
00076 extern void *LMalloc(size_t size);
00077 
00092 extern void *LFree(void *ptr);
00093 
00113 extern void *LRealloc(void *ptr,size_t size);
00114 
00115 
00134 template<typename T>inline T *ALLOC(size_t nelem)
00135     {  return((T*)LMalloc(nelem*sizeof(T)));  }
00136 
00155 template<typename T>inline T *FREE(T *ptr)
00156     {  return((T*)LFree(ptr));  }
00157 
00182 template<typename T>inline T *REALLOC(T *ptr,size_t nelem)
00183     {  return((T*)LRealloc(ptr,nelem*sizeof(T)));  }
00184 
00185 
00192 inline void *operator new(size_t size)
00193     {  return(LMalloc(size));  }
00194 
00214 inline void *operator new(size_t /*size*/,void *ptr)
00215     {  return(ptr);  }
00216 
00225 inline void operator delete(void *ptr)
00226     {  LFree(ptr);  }
00227 
00235 template<typename T> inline void DELETE(T* &ptr)
00236     {  if(ptr)  {  delete ptr;  ptr=NULL;  }  }
00237 
00238 
00247 inline void *operator new[](size_t size)
00248     {  return(LMalloc(size));  }
00249 
00259 inline void operator delete[](void *ptr)
00260     {  LFree(ptr);  }
00261 
00269 template<typename T> inline void DELARRAY(T* &ptr)
00270     {  if(ptr)  {  delete[] ptr;  ptr=NULL;  }  }
00271 
00272 #endif  /* _SRC_SALLOC_H_ */

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5