47 int BESMemoryGlobalArea::_counter = 0 ;
48 unsigned long BESMemoryGlobalArea::_size = 0 ;
49 void* BESMemoryGlobalArea::_buffer = 0 ;
58 string key =
"BES.Memory.GlobalArea." ;
76 if( (eps==
"") || (mhs==
"") || (verbose==
"") || (control_heap==
"") )
78 string line =
"cannot determine memory keys." ;
79 line += (string)
"Please set values for"
80 +
" BES.Memory.GlobalArea.EmergencyPoolSize,"
81 +
" BES.Memory.GlobalArea.MaxiumumHeapSize,"
82 +
" BES.Memory.GlobalArea.Verbose, and"
83 +
" BES.Memory.GlobalArea.ControlHeap"
84 +
" in the BES configuration file." ;
92 unsigned int emergency=atol(eps.c_str());
94 if( control_heap ==
"yes" )
96 unsigned int max = atol(mhs.c_str());
97 BESDEBUG(
"bes",
"Initializing emergency heap to "
98 << (
long int)emergency <<
" MB" << endl ) ;
99 BESDEBUG(
"bes",
"Initializing max heap size to "
100 << (
long int)(max+1) <<
" MB" << endl ) ;
102 << (
long int)emergency
103 <<
" and heap size to " ;
105 <<
" megabytes" << endl ;
106 if( emergency > max )
108 string s = string (
"BES: " )
109 +
"unable to start since the emergency "
110 +
"pool is larger than the maximum size of "
115 log_limits(
"before setting limits: " ) ;
116 limit.rlim_cur = megabytes( max + 1 ) ;
117 limit.rlim_max = megabytes( max + 1 ) ;
125 if( setrlimit( RLIMIT_DATA, &limit ) < 0 )
127 string s = string(
"BES: " )
128 +
"Could not set limit for the heap "
129 +
"because " + strerror(errno) +
"\n" ;
132 s = s +
"Attempting to increase the soft/hard "
133 +
"limit above the current hard limit, "
134 +
"must be superuser\n" ;
139 log_limits(
"after setting limits: " ) ;
141 _buffer = malloc( megabytes( max ) ) ;
144 string s = string(
"BES: " )
145 +
"cannot get heap of size "
146 + mhs +
" to start running" ;
156 string s =
"Emergency pool is larger than 10 Megabytes";
161 _size = megabytes( emergency ) ;
163 _buffer = malloc( _size ) ;
166 string s = (string)
"BES: cannot expand heap to "
167 + eps +
" to start running" ;
186 cerr <<
"BES: unable to start properly because "
193 cerr <<
"BES: unable to start: undefined exception happened\n" ;
211 BESMemoryGlobalArea::log_limits(
const string &msg )
213 if( getrlimit( RLIMIT_DATA, &limit ) < 0 )
216 << strerror( errno ) << endl ;
220 if( limit.rlim_cur == RLIM_INFINITY )
225 << (
long int)limit.rlim_cur
227 << (
long int)(limit.rlim_cur)/(
MEGABYTE)
228 <<
" MB - may be rounded up)" << endl ;
229 if( limit.rlim_max == RLIM_INFINITY )
234 << (
long int)limit.rlim_max
236 << (
long int)(limit.rlim_cur)/(
MEGABYTE)
237 <<
" MB - may be rounded up)" << endl ;
254 _buffer = malloc( _size ) ;
272 << (
void *)
this <<
")" << endl ;
276 << (
void *)_buffer << endl ;