JVM Sun сделала, чтобы PermGen расположил с интервалами зафиксированный, и в конечном счете это все использовало (да, по-видимому из-за ошибки в classloader-связанном коде) => OOM.
, Если можно использовать JVM другого поставщика (например, Weblogic один), он динамично расширяет пространство PermGen, таким образом, Вы никогда не будете получать permgen-связанный OOM.
One way to do it:
stringstream(str) >> ulongVariable;
You can use strtoul with no problem. The function returns an unsigned long. If convertion can not be performed the function return 0. If the correct long value is out of range the function return ULONG_MAX and the errno global variable is set to ERANGE.
If you can use the boost libraries (www.boost.org) look at the conversion library - it's a header only include
#include "boost/lexical_cast.hpp"
then all you need to do is
unsigned long ul = boost::lexical_cast<unsigned long>(str);
template <class T>
T strToNum(const std::string &inputString,
std::ios_base &(*f)(std::ios_base&) = std::dec)
{
T t;
std::istringstream stringStream(inputString);
if ((stringStream >> f >> t).fail())
{
throw runtime_error("Invalid conversion");
}
return t;
}
// Example usage
unsigned long ulongValue = strToNum<unsigned long>(strValue);
int intValue = strToNum<int>(strValue);
int intValueFromHex = strToNum<int>(strHexValue,std::hex);
unsigned long ulOctValue = strToNum<unsigned long>(strOctVal, std::oct);
Jeffrey Stedfast has a beautiful post about writing int parser routines for Mono (in C).
It generates code that uses uses native types (you need 32 bit to parse 32 bit) and error codes for overflow.
Надежный путь будет напишите статическую функцию и используйте ее
bool str2Ulong(const string& str,unsigned long & arValue)
{
char *tempptr=NULL;
arValue=strtoul(str,tempptr,10);
return ! (arValue==0 && tempptr==str.c_str());
}