亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: epoll的奇怪問題---【已解決】 [打印本頁]

作者: banceleung    時(shí)間: 2010-03-15 09:14
標(biāo)題: epoll的奇怪問題---【已解決】
本帖最后由 banceleung 于 2010-03-15 09:50 編輯

先貼代碼后解釋 #include <pthread.h>

  1. #include <sys/epoll.h>

  2. class CNetMsgImp

  3. {

  4. public:        

  5.         struct epoll_event m_events[12];

  6.         //char temp[1000]; //-------!!!!!!!!!!!!----------        

  7.         int m_kdpfd;

  8.         CNetMsgImp();

  9.         ~CNetMsgImp();

  10. };

  11. CNetMsgImp::CNetMsgImp()

  12. {               

  13.         m_kdpfd = epoll_create(11+11);  

  14.   m_events[11].events = 11;

  15.   epoll_wait(m_kdpfd,m_events, 20, -1);   

  16. }

  17. int main(int argc, char* argv[])

  18. {               

  19.         CNetMsgImp* netMsgImg = new CNetMsgImp;        

  20. }
復(fù)制代碼
g++ -pthread -o test test.cpp
valgrind --tool=memcheck ./test


==11054== Memcheck, a memory error detector.
==11054== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==11054== Using LibVEX rev 1804, a library for dynamic binary translation.
==11054== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==11054== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation framework.
==11054== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==11054== For more details, rerun with: -v
==11054==
==11054== Syscall param epoll_wait(events) points to unaddressable byte(s)
==11054==    at 0x40007F2: (within /lib/ld-2.7.so)
==11054==    by 0x8048623: main (in /mnt/hgfs/NetFrameL/test)
==11054==  Address 0x42c10bc is 0 bytes after a block of size 148 alloc'd
==11054==    at 0x4023294: operator new(unsigned) (vg_replace_malloc.c:224)
==11054==    by 0x8048615: main (in /mnt/hgfs/NetFrameL/test) #include <pthread.h>

  1. #include <sys/epoll.h>

  2. class CNetMsgImp

  3. {

  4. public:        

  5.         struct epoll_event m_events[12];        

  6.         char temp[1000];

  7.         int m_kdpfd;

  8.         CNetMsgImp();

  9.         ~CNetMsgImp();

  10. };

  11. CNetMsgImp::CNetMsgImp()

  12. {               

  13.         m_kdpfd = epoll_create(11+11);  

  14.   m_events[11].events = 11;

  15.   epoll_wait(m_kdpfd,m_events, 20, -1);   

  16. }

  17. int main(int argc, char* argv[])

  18. {        

  19.         CNetMsgImp* netMsgImg = new CNetMsgImp;        

  20. }
復(fù)制代碼
g++ -pthread -o test test.cpp
valgrind --tool=memcheck ./test


==11092== Memcheck, a memory error detector.
==11092== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==11092== Using LibVEX rev 1804, a library for dynamic binary translation.
==11092== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==11092== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation framework.
==11092== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==11092== For more details, rerun with: -v
==11092==

如上,如果在類里不加那個(gè)char temp[1000];則valgrind會(huì)報(bào)錯(cuò),運(yùn)行時(shí)程序會(huì)有棧錯(cuò)誤,明確的說會(huì)侵占對(duì)象內(nèi)存,改變現(xiàn)有對(duì)象的內(nèi)部數(shù)據(jù)。
以上代碼是原有程序的簡化,已能說明問題。

  1. #include <sys/epoll.h>

  2. class A

  3. {

  4.         public:

  5.         int a;

  6.         struct epoll_event m_events[12];

  7.         //char temp[1000];

  8.         A();

  9.         ~A();

  10. };

  11. A::A()

  12. {

  13.         a = epoll_create(11+11);  

  14.         epoll_wait(a,m_events, 20, -1);   

  15. }

  16. int main(void)

  17. {

  18.         A* b = new A;

  19. }
復(fù)制代碼
來個(gè)更簡單的,問題照舊。
作者: hellioncu    時(shí)間: 2010-03-15 09:29
struct epoll_event m_events[12];

epoll_wait(a,m_events, 20, -1);

上面是12,下面是20
作者: peidright    時(shí)間: 2010-03-15 09:32
{:3_191:},奇怪,我這里運(yùn)行沒有問題。。。
ubuntu 64bit gcc 4.33
作者: banceleung    時(shí)間: 2010-03-15 09:36
回復(fù) 2# hellioncu


       大意了大意了,多謝!
作者: rain_fish    時(shí)間: 2010-03-15 09:39
epoll_wait(a,m_events, 12, -1);
作者: rain_fish    時(shí)間: 2010-03-15 09:40
[root@localhost test]# valgrind --tool=memcheck ./epoll
==18449== Memcheck, a memory error detector
==18449== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==18449== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==18449== Command: ./epoll
==18449==
==18449==
==18449== HEAP SUMMARY:
==18449==     in use at exit: 148 bytes in 1 blocks
==18449==   total heap usage: 1 allocs, 0 frees, 148 bytes allocated
==18449==
==18449== LEAK SUMMARY:
==18449==    definitely lost: 0 bytes in 0 blocks
==18449==    indirectly lost: 0 bytes in 0 blocks
==18449==      possibly lost: 0 bytes in 0 blocks
==18449==    still reachable: 148 bytes in 1 blocks
==18449==         suppressed: 0 bytes in 0 blocks
==18449== Rerun with --leak-check=full to see details of leaked memory
==18449==
==18449== For counts of detected and suppressed errors, rerun with: -v
==18449== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from
作者: peidright    時(shí)間: 2010-03-15 09:42
”hgfs/NetFrameL“
...呵呵!。 準(zhǔn)備開源么。。
作者: banceleung    時(shí)間: 2010-03-15 09:49
回復(fù) 7# peidright


    老板沒意見的話我也倒是樂意。

   vmware--tool的默認(rèn)路徑。
作者: chary8088    時(shí)間: 2010-03-15 09:55
LS正確
作者: peidright    時(shí)間: 2010-03-15 10:10
回復(fù) 8# banceleung
搜google發(fā)現(xiàn)了。開始以為是 high speed google file system...
作者: qqrilxk    時(shí)間: 2011-12-19 17:10
學(xué)習(xí)一下




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2