由于某些原因,我的代码是segfaulting。 这是相关的代码。
typedef boost::singleton_pool<httpHandler,sizeof(httphandler)> httpHandlerpool;
typedef boost::singleton_pool<Conn ,sizeof(Conn)> connpool;
void *httphandler::operator new(size_t size)
{
return httpHandlerpool::malloc();
}
//there is a corresponding delete as well.
void *Conn::operator new(size_t size)
{
return connpool::malloc();
}
//there is a corresponding delete as well.
Conn* httpHandler::getFreeConn()
{
Conn *c=0;
c = new Conn(); //
memset(c,0,sizeof *c); // This is where looks like some issue is there.
return c
}
在我执行新Conn的代码中,将分配多少内存?它是'sizeof struct Conn`吗? memset我做错了什么?有必要吗? 感谢。