由于某些原因,我的代码出现了段错误。这是相关的代码。
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 上做错了什么?有必要吗?谢谢。