log4cplus内存泄漏起因之一 结构体字节对齐 log4cplus结构体使用的是8字节对齐
2012-12-15 12:33
330 查看
int main()
{
string commonLayout = "%d{%Y-%m-%d %H:%M:%S %Q} | %p | %t | %m [%l] %n";
string logPath = "d:\\testlog.txt";
std::auto_ptr<Layout> layout(new PatternLayout(LOG4CPLUS_TEXT(commonLayout)));
SharedAppenderPtr appender(new FileAppender(LOG4CPLUS_TEXT(logPath), std::ios_base::app));
appender->setLayout(layout);
Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("root.test"));
logger.setLogLevel(DEBUG_LOG_LEVEL);
logger.addAppender(appender);
LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("run"));
return 0;
}
当结构体字节对齐使用默认的时候 程序运行正常
log4cplus使用的是8字节对齐方式, 如果程序设置成其他字节对齐 就会出现如下错误:
还会出现如下提示:
HEAP[testLog4.exe]: Heap block at 004EAB60 modified at 004EACD7 past requested size of 16f
Windows has triggered a breakpoint in testLog4.exe.
This may be due to a corruption of the heap, which indicates a bug in testLog4.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while testLog4.exe has focus.
The output window may have more diagnostic information.
又是一个结构体字节对齐导致的错误
{
string commonLayout = "%d{%Y-%m-%d %H:%M:%S %Q} | %p | %t | %m [%l] %n";
string logPath = "d:\\testlog.txt";
std::auto_ptr<Layout> layout(new PatternLayout(LOG4CPLUS_TEXT(commonLayout)));
SharedAppenderPtr appender(new FileAppender(LOG4CPLUS_TEXT(logPath), std::ios_base::app));
appender->setLayout(layout);
Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("root.test"));
logger.setLogLevel(DEBUG_LOG_LEVEL);
logger.addAppender(appender);
LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("run"));
return 0;
}
当结构体字节对齐使用默认的时候 程序运行正常
log4cplus使用的是8字节对齐方式, 如果程序设置成其他字节对齐 就会出现如下错误:
还会出现如下提示:
HEAP[testLog4.exe]: Heap block at 004EAB60 modified at 004EACD7 past requested size of 16f
Windows has triggered a breakpoint in testLog4.exe.
This may be due to a corruption of the heap, which indicates a bug in testLog4.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while testLog4.exe has focus.
The output window may have more diagnostic information.
又是一个结构体字节对齐导致的错误
相关文章推荐
- log4cplus内存泄漏起因之一 结构体字节对齐 log4cplus结构体使用的是8字节对齐
- 结构体(struct)的使用、内存分布以及字节对齐测试总结
- 结构体(struct)的使用、内存分布以及字节对齐测试总结
- 结构体字节对齐
- (四)结构体、共用体、枚举、字节对齐
- C/C++结构体字节对齐详解
- 结构体字节对齐
- 结构体字节对齐
- STM32学习笔记10——stm32中结构体字节对齐问题
- 结构体字节对齐规则
- 结构体字节对齐
- 语言 内存中结构体字节对齐
- 结构体字节对齐(感谢 @海子)
- 有关结构体字节对齐方式
- 结构体字节对齐
- 常考笔试题,详细解剖C++运算符sizeof()的使用及字节对齐问题
- C语言结构体的字节对齐原则
- 笔试 sizeof 字节对齐 结构体
- 结构体字节对齐详解
- 结构体字节对齐