一個(gè)測(cè)試ACE各種內(nèi)存分配策略規(guī)劃效率的程序_第1頁(yè)
一個(gè)測(cè)試ACE各種內(nèi)存分配策略規(guī)劃效率的程序_第2頁(yè)
一個(gè)測(cè)試ACE各種內(nèi)存分配策略規(guī)劃效率的程序_第3頁(yè)
一個(gè)測(cè)試ACE各種內(nèi)存分配策略規(guī)劃效率的程序_第4頁(yè)
一個(gè)測(cè)試ACE各種內(nèi)存分配策略規(guī)劃效率的程序_第5頁(yè)
已閱讀5頁(yè),還剩22頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、一個(gè)測(cè)試ACE各種內(nèi)存分配策略效率的程序64位平臺(tái)C/C+研發(fā)注意事項(xiàng)在/en/l/上例出了28個(gè)在64位平臺(tái)上使用C/C+釬發(fā)的注意事項(xiàng),對(duì)于進(jìn)入64位時(shí)代的程序員應(yīng)該去看看這28個(gè)事項(xiàng),這些英文讀物對(duì)于有C/C+鋤底的朋友讀起來(lái)應(yīng)該并不難,我估計(jì)大約20-30分鐘可以精讀完一篇(或者更快),下面是這28個(gè)注意事項(xiàng)的列表。相信對(duì)大家一點(diǎn)有幫助。Lesson01.What64-bitsystemsare.Lesson02.Stestmallocloop10000usetime32.950000stestcachedloop10000usetime1.730000stestmallocmmapl

2、oop10000usetime5.050000stestmallocmmapliteloop10000usetime5.030000stestmalloclocalloop10000usetime0.620000stestmalloclocalmutexloop10000usetime4.250000stestmalloc_brk_mutexloop10000usetime0.600000stestmallocsharemutexloop10000usetime4.360000s#includeace/OS_NS_stdio.h#includeace/OS_NS_string.h#includ

3、eace/Malloc_T.h#includeace/Null_Mutex.h#includetime.h#includeassert.hclock_t_begin;clock_t_end;int_loop;#defineBEGIN(n)_begin=clock();for(_loop=0;_loop_loop+)#defineEND(s)_end=clock();printf(%sloop%dusetime%lfs,s,_loop,(double)(_end-_begin)/(double)CLOCKS_PER_SEC);constintMAXSIZE=1024;void*p1000;voi

4、dtestmalloc()inti=0;for(i=0;i1000;i+)pi=malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)free(pi);typedefcharBLOCKMAXSIZE;typedefACE_Dynamic_Cached_AllocatorACE_SYNCH_NULL_MUTEXAllocator;Allocatorcache(1000,MAXSIZE);voidtestcached()inti=0;for(i=0;i1000;i+)pi=cache.malloc(MAXSIZE);assert(pi!=NULL);f

5、or(i=0;i1000;i+)cache.free(pi);typedefACE_MallocACE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mmap;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_NULL_MUTEXmalloc_local;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_local_mutex;typedefACE_MallocACE_SHARED_MEMORY_POOL,ACE_SYNCH_MUTEXmall

6、oc_share_mutex;typedefACE_MallocACE_SBRK_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_sbrk_mutex;typedefACE_MallocACE_LITE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mmap_lite;templateclassTvoidtestmalloc(Tml)inti=0;for(i=0;i1000;i+)pi=ml.malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)ml.free(pi);pi=NULL;intmai

7、n(intargc,char*argv)BEGIN(10000)testmalloc();END(testmalloc)BEGIN(10000)testcached();END(testcached)ACE_MMAP_Memory_Pool_Optionsoptions(ACE_DEFAULT_BASE_ADDR,ACE_MMAP_Memory_Pool_Options:ALWAYS_FIXED,1024*10000);malloc_mmapmm(hello,hello,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BE

8、GIN(10000)testmalloc(mm);END(testmallocmmap)mm.remove();malloc_mmap_litemml(helloq,helloq,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mml);END(testmallocmmaplite)mml.remove();malloc_localml(hello1/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)te

9、stmalloc(ml);END(testmalloclocal)ml.remove();malloc_local_mutexmlm(hello2/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlm);END(testmalloclocalmutex)mlm.remove();malloc_localmlb(hellob/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlb);END(testm

10、alloc_brk_mutex)mlb.remove();ACE_Shared_Memory_Pool_Optionsoptions2(ACE_DEFAULT_BASE_ADDR,1,ACE_DEFAULT_FILE_PERMS,1,1024*1200);malloc_share_mutexmsm(hello3,hello3,options2);BEGIN(10000)testmalloc(msm);END(testmallocsharemutex)msm.remove();return0;來(lái)自:/blog/cns!F66D6083FD44CD13!183.entrytestmallocloo

11、p10000usetime32.950000stestcachedloop10000usetime1.730000stestmallocmmaploop10000usetime5.050000stestmallocmmapliteloop10000usetime5.030000stestmalloclocalloop10000usetime0.620000stestmalloclocalmutexloop10000usetime4.250000stestmalloc_brk_mutexloop10000usetime0.600000stestmallocsharemutexloop10000u

12、setime4.360000s#includeace/OS_NS_stdio.h#includeace/OS_NS_string.h#includeace/Malloc_T.h#includeace/Null_Mutex.h#includetime.h#includeassert.hclock_t_begin;clock_t_end;int_loop;#defineBEGIN(n)_begin=clock();for(_loop=0;_loop_loop+)#defineEND(s)_end=clock();printf(%sloop%dusetime%lfs,s,_loop,(double)

13、(_end-_begin)/(double)CLOCKS_PER_SEC);constintMAXSIZE=1024;void*p1000;voidtestmalloc()inti=0;for(i=0;i1000;i+)pi=malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)free(pi);typedefcharBLOCKMAXSIZE;typedefACE_Dynamic_Cached_AllocatorACE_SYNCH_NULL_MUTEXAllocator;Allocatorcache(1000,MAXSIZE);voidtestca

14、ched()inti=0;for(i=0;i1000;i+)pi=cache.malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)cache.free(pi);typedefACE_MallocACE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mmap;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_NULL_MUTEXmalloc_local;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_MUTEXmallo

15、c_local_mutex;typedefACE_MallocACE_SHARED_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_share_mutex;typedefACE_MallocACE_SBRK_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_sbrk_mutex;typedefACE_MallocACE_LITE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mmap_lite;templateclassTvoidtestmalloc(Tml)inti=0;for(i=0;i1000;i+)pi=ml.mal

16、loc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)ml.free(pi);pi=NULL;intmain(intargc,char*argv)BEGIN(10000)testmalloc();END(testmalloc)BEGIN(10000)testcached();END(testcached)ACE_MMAP_Memory_Pool_Optionsoptions(ACE_DEFAULT_BASE_ADDR,ACE_MMAP_Memory_Pool_Options:ALWAYS_FIXED,1024*10000);malloc_mmapmm(h

17、ello,hello,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mm);END(testmallocmmap)mm.remove();malloc_mmap_litemml(helloq,helloq,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mml);END(testmallocmmaplite)mml.remove();malloc_localm

18、l(hello1/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(ml);END(testmalloclocal)ml.remove();malloc_local_mutexmlm(hello2/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlm);END(testmalloclocalmutex)mlm.remove();malloc_localmlb(hellob/fprintf(stderr

19、,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlb);END(testmalloc_brk_mutex)mlb.remove();ACE_Shared_Memory_Pool_Optionsoptions2(ACE_DEFAULT_BASE_ADDR,1,ACE_DEFAULT_FILE_PERMS,1,1024*1200);malloc_share_mutexmsm(hello3,hello3,options2);BEGIN(10000)testmalloc(msm);END(testmallocsharemutex)

20、msm.remove();return0;來(lái)自:/blog/cns!F66D6083FD44CD13!183.entrytestmallocloop10000usetime32.950000stestcachedloop10000usetime1.730000stestmallocmmaploop10000usetime5.050000stestmallocmmapliteloop10000usetime5.030000stestmalloclocalloop10000usetime0.620000stestmalloclocalmutexloop10000usetime4.250000ste

21、stmalloc_brk_mutexloop10000usetime0.600000stestmallocsharemutexloop10000usetime4.360000s#includeace/OS_NS_stdio.h#includeace/OS_NS_string.h#includeace/Malloc_T.h#includeace/Null_Mutex.h#includetime.h#includeassert.hclock_t_begin;clock_t_end;int_loop;#defineBEGIN(n)_begin=clock();for(_loop=0;_loop_lo

22、op+)#defineEND(s)_end=clock();printf(%sloop%dusetime%lfs,s,_loop,(double)(_end-_begin)/(double)CLOCKS_PER_SEC);constintMAXSIZE=1024;void*p1000;voidtestmalloc()inti=0;for(i=0;i1000;i+)pi=malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)free(pi);typedefcharBLOCKMAXSIZE;typedefACE_Dynamic_Cached_Alloc

23、atorACE_SYNCH_NULL_MUTEXAllocator;Allocatorcache(1000,MAXSIZE);voidtestcached()inti=0;for(i=0;i1000;i+)pi=cache.malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)cache.free(pi);typedefACE_MallocACE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mmap;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_NULL_MUTE

24、Xmalloc_local;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_local_mutex;typedefACE_MallocACE_SHARED_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_share_mutex;typedefACE_MallocACE_SBRK_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_sbrk_mutex;typedefACE_MallocACE_LITE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mma

25、p_lite;templateclassTvoidtestmalloc(Tml)inti=0;for(i=0;i1000;i+)pi=ml.malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)ml.free(pi);pi=NULL;intmain(intargc,char*argv)BEGIN(10000)testmalloc();END(testmalloc)BEGIN(10000)testcached();END(testcached)ACE_MMAP_Memory_Pool_Optionsoptions(ACE_DEFAULT_BASE_A

26、DDR,ACE_MMAP_Memory_Pool_Options:ALWAYS_FIXED,1024*10000);malloc_mmapmm(hello,hello,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mm);END(testmallocmmap)mm.remove();malloc_mmap_litemml(helloq,helloq,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGI

27、N(10000)testmalloc(mml);END(testmallocmmaplite)mml.remove();malloc_localml(hello1/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(ml);END(testmalloclocal)ml.remove();malloc_local_mutexmlm(hello2/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlm);EN

28、D(testmalloclocalmutex)mlm.remove();malloc_localmlb(hellob/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlb);END(testmalloc_brk_mutex)mlb.remove();ACE_Shared_Memory_Pool_Optionsoptions2(ACE_DEFAULT_BASE_ADDR,1,ACE_DEFAULT_FILE_PERMS,1,1024*1200);malloc_share_mutexmsm(hell

29、o3,hello3,options2);BEGIN(10000)testmalloc(msm);END(testmallocsharemutex)msm.remove();return0;來(lái)自:/blog/cns!F66D6083FD44CD13!183.entrytestmallocloop10000usetime32.950000stestcachedloop10000usetime1.730000stestmallocmmaploop10000usetime5.050000stestmallocmmapliteloop10000usetime5.030000stestmallocloca

30、lloop10000usetime0.620000stestmalloclocalmutexloop10000usetime4.250000stestmalloc_brk_mutexloop10000usetime0.600000stestmallocsharemutexloop10000usetime4.360000s#includeace/OS_NS_stdio.h#includeace/OS_NS_string.h#includeace/Malloc_T.h#includeace/Null_Mutex.h#includetime.h#includeassert.hclock_t_begi

31、n;clock_t_end;int_loop;#defineBEGIN(n)_begin=clock();for(_loop=0;_loop_loop+)#defineEND(s)_end=clock();printf(%sloop%dusetime%lfs,s,_loop,(double)(_end-_begin)/(double)CLOCKS_PER_SEC);constintMAXSIZE=1024;void*p1000;voidtestmalloc()inti=0;for(i=0;i1000;i+)pi=malloc(MAXSIZE);assert(pi!=NULL);for(i=0;

32、i1000;i+)free(pi);typedefcharBLOCKMAXSIZE;typedefACE_Dynamic_Cached_AllocatorACE_SYNCH_NULL_MUTEXAllocator;Allocatorcache(1000,MAXSIZE);voidtestcached()inti=0;for(i=0;i1000;i+)pi=cache.malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)cache.free(pi);typedefACE_MallocACE_MMAP_MEMORY_POOL,ACE_SYNCH_MU

33、TEXmalloc_mmap;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_NULL_MUTEXmalloc_local;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_local_mutex;typedefACE_MallocACE_SHARED_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_share_mutex;typedefACE_MallocACE_SBRK_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_sbrk_m

34、utex;typedefACE_MallocACE_LITE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mmap_lite;templateclassTvoidtestmalloc(Tml)inti=0;for(i=0;i1000;i+)pi=ml.malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)ml.free(pi);pi=NULL;intmain(intargc,char*argv)BEGIN(10000)testmalloc();END(testmalloc)BEGIN(10000)testcache

35、d();END(testcached)ACE_MMAP_Memory_Pool_Optionsoptions(ACE_DEFAULT_BASE_ADDR,ACE_MMAP_Memory_Pool_Options:ALWAYS_FIXED,1024*10000);malloc_mmapmm(hello,hello,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mm);END(testmallocmmap)mm.remove();malloc_mmap_litemml(hello

36、q,helloq,options);/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mml);END(testmallocmmaplite)mml.remove();malloc_localml(hello1/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(ml);END(testmalloclocal)ml.remove();malloc_local_mutexmlm(hello2/fprintf

37、(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlm);END(testmalloclocalmutex)mlm.remove();malloc_localmlb(hellob/fprintf(stderr,%dchuncks,ml.avail_chunks(MAXSIZE);BEGIN(10000)testmalloc(mlb);END(testmalloc_brk_mutex)mlb.remove();ACE_Shared_Memory_Pool_Optionsoptions2(ACE_DEFAULT_B

38、ASE_ADDR,1,ACE_DEFAULT_FILE_PERMS,1,1024*1200);malloc_share_mutexmsm(hello3,hello3,options2);BEGIN(10000)testmalloc(msm);END(testmallocsharemutex)msm.remove();return0;來(lái)自:/blog/cns!F66D6083FD44CD13!183.entrytestmallocloop10000usetime32.950000stestcachedloop10000usetime1.730000stestmallocmmaploop10000

39、usetime5.050000stestmallocmmapliteloop10000usetime5.030000stestmalloclocalloop10000usetime0.620000stestmalloclocalmutexloop10000usetime4.250000stestmalloc_brk_mutexloop10000usetime0.600000stestmallocsharemutexloop10000usetime4.360000s#includeace/OS_NS_stdio.h#includeace/OS_NS_string.h#includeace/Mal

40、loc_T.h#includeace/Null_Mutex.h#includetime.h#includeassert.hclock_t_begin;clock_t_end;int_loop;#defineBEGIN(n)_begin=clock();for(_loop=0;_loop_loop+)#defineEND(s)_end=clock();printf(%sloop%dusetime%lfs,s,_loop,(double)(_end-_begin)/(double)CLOCKS_PER_SEC);constintMAXSIZE=1024;void*p1000;voidtestmal

41、loc()inti=0;for(i=0;i1000;i+)pi=malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i1000;i+)free(pi);typedefcharBLOCKMAXSIZE;typedefACE_Dynamic_Cached_AllocatorACE_SYNCH_NULL_MUTEXAllocator;Allocatorcache(1000,MAXSIZE);voidtestcached()inti=0;for(i=0;i1000;i+)pi=cache.malloc(MAXSIZE);assert(pi!=NULL);for(i=0;i

42、1000;i+)cache.free(pi);typedefACE_MallocACE_MMAP_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_mmap;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_NULL_MUTEXmalloc_local;typedefACE_MallocACE_LOCAL_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_local_mutex;typedefACE_MallocACE_SHARED_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_share_mutex;typedefACE_MallocACE_SBRK_MEMORY_POOL,ACE_SYNCH_MUTEXmalloc_sbrk_

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論