00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GUST_NEW_H
00021 #define GUST_NEW_H
00022
00023 #if defined(_MSC_VER) || defined(__WXMSW__)
00024 #ifdef new
00025 #undef new
00026 #endif
00027
00028 #else
00029
00030 #endif
00031
00032 #define reserve_stack(T,n) (T *)alloca((n)*sizeof(T))
00033
00034 namespace gust {
00035
00036
00037
00038
00039
00040
00041
00042 enum Storage
00043 {
00044 dumb,
00045 place,
00046 heap,
00047 pool
00048 };
00049
00050 inline void release( void *buf, unsigned int t, unsigned int s )
00051 {
00052 if( (t <= place) || (buf == NULL) ) return;
00053 if( t == heap ) { free(buf); return; }
00054 PreferPoolFree( buf, s );
00055 }
00056
00057 inline void *reserve_global( size_t s, size_t *ret_s )
00058 {
00059 void *p = malloc( s );
00060 if( p == NULL ) throw gul::AllocError();
00061 *ret_s = s;
00062 return(p);
00063 }
00064
00065 inline void *reserve_pool( size_t s, size_t *ret_s )
00066 {
00067 void *p = PreferPoolAlloc( s, ret_s);
00068 if( p == NULL ) throw gul::AllocError();
00069 return(p);
00070 }
00071
00072
00073
00074
00075
00076 }
00077
00078
00079
00080 #endif
00081