




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、一個測試ace各種內(nèi)存分配策略效率的程序個測試ace各種內(nèi)存分配策略效率的程64位平臺c/c+開發(fā)注意事項在/en/1/上例出了 28個在64位平臺上使川c/c+開發(fā)的注意事項,對于進入64位時代 的程序員應(yīng)該去看看這28個事項,這些英文讀物對于冇c/c+功底的朋友讀起來應(yīng)該并不 難,我估計大約20-30分鐘可以精讀完一篇(或者更快),下面是這28個注意事項的列 表。相信對大家一點有幫助。lesso n 01. what 64-bit systems are. les so n 02. s testmalloc loop 10000 use time 32.950000 stestcached
2、 loop 10000 use time 1.730000 stestmallocmmap loop 10000 use time 5.050000 s testmallocmmaplite loop 10000 use time 5. 030000 s testmalloclocal loop 10000 use time 0. 620000 stestmalloclocalmutex loop 10000 use time 4.250000 s testmalloc_brk_mutex loop 10000 use time 0. 600000 s testmallocsharemutex
3、 loop 10000 use time 4. 360000 s#inelude ace/0s_ns stdio. h#include ace/os ns stringh#inelude ace/malloc_t. h#inelude ace/null mutexh ttinclude time, h#inelude asserth clock t begin;clock t end;mbint loop;#define begin(n)begin = clock();for ( loop = 0; _ 1 oop _loop+) #define end(s) _end = clocko ;p
4、rintf ( %s loop %d use time %lf s , s, loop , (double) ( end - begin) / (double)clocks per sec); const int maxsize = 1024;void *p1000;void testmalloc()int i 二 0;for (i = 0; i 1000; i+) pi = malloc(maxsize); assert(pi != null); for (i = 0; i 1000; i+) free(pi);tvpedef char blockmaxsize;typedef ace_dy
5、namic_cached_allocatorace_syncii_null_mutex allocator;allocator cache(1000, maxsize);void testcachcd () int i 二 0;for (i = 0; i 1000; i+) pi = cache, malloc(maxsize); assert(pi != null); for (i = 0; i 1000; i+)!cache. free(pi);typedef ace malloc ace mmap memory pool, ace synch mutex malloc mmap;type
6、def ace_malloc ace丄ocal_memory_pool, ace_synch_null_mutex malloc_local;typedef ace malloc ace local memory pool, ace synch mutex malloc local mutex;typedef ace malloc ace shared memory pool, ace synch mutex malloc_share_mutex;typedef ace_malloc ace_sbrk_memory_pool, ace_synch_mutex malloc_sbrk_mutex
7、;typedef ace_malloc ace_lite_mmap_memory_pool, ace synch mutex malloc mmap lite;template class t void testmalloc(t ml)int i = 0;for (i = 0; i 1000; i+) pi = ml. malloc(maxsize); assert (pi != null); for (i = 0; i 1000; i+) ml.free(pi);pi = null;int main(int argc, char* argv) begin (10000)testmalloc(
8、);end( testmalloc ) begin(ioooo) testcachodo ;end( testcached ) ace_mmap_memory_pool_0ptions options(ace_default_base_addr,ace_mmap_memory_pool_options:always_ftxed, 1024 * 10000 );malloc_mmap nim( hello , hello , options);/fprintf (stderr, %d chuncks , ml. avail_chunks(maxsize);begin(10000)testmall
9、oc(mm);exd( testmallocmmap )mm.remove(); malloc_mmap_lite mml( helloq , helloq , options);/fprintf (stderr, %d chuncks , ml. avail_chunks(maxsize); begin(10000)testmalloc(mml);end( testmallocmmaplite )mml. remove(); malloc_local ml( hellol/fprintf (stderr, %d chuncks , ml. ava訂_chunks(maxsize); begi
10、n(10000)testmalloc(ml);end( testmalloclocal )ml. remove(); malloc_local_mutex mlm( hello2/fprintf(stderr, %d chuncks , ml. avail_chunks(maxsize); begin(10000)testmal1oc(mlm);exd( testmalloclocalmutex )mlm< remove(); malloc_local mlb( hellob/fprintf (stderr, %d chuncks , ml. avail_chunks(maxsize);
11、begin(10000)testmalloc(mlb);end( testmalloc_brk_mutex ) mlb.removeo;ace shared memory pool options options2(ace default base addr, 1,ace_default_file_perfs, 1, 1024 * 1200 );malloc_share_mutex msm( hello3 , hello3 , options2); begin(ioooo)testmdlloc(msm);exd( testmal1ocsharemutex )msm. remove();retu
12、rn 0;來自:/blog/cns!f66d6083fd44cd13! 183. entry testmalloc loop 10000 use time 32. 950000 s testcached loop 10000 use time 1. 730000 stestmallocimnap loop 10000 use time 5. 050000 s testmallocnimaplite loop 10000 use time 5. 030000 s testmalloclocal loop 10000 use time 0. 620000 stestmalloclocalmutex
13、 loop 10000 use time 4.250000 stestmalloc brk mutex loop 10000 use time 0. 600000 s testmalloesharemutex loop 10000 use time 4. 360000 sttinclude ace/os_ns_stdio. h#include ace/0s_ns_string. h#include ace/mal1oc_t. h#inelude ace/null_mutex< h ttinclude time.h include assert- h clock_t _begin;eloe
14、kt _end;int _loop;#define begin(n)_begin 二 clock();for (loop = 0; _1oop _loop+) define end(s) _end = clock() ;printf( %s loop %d use time %lf s , s, _loop , (double) (_end -_begin) / (double)clocks_per_sec); const int maxsize = 1024;void *p1000;void testmalloc()int i 二 0;for (i = 0; i 1000; i+) pi =
15、 malloc(maxsize); assert(pi != null); for (i = 0; i 1000; i卄)free(pi);typedef char blockmaxstze;typeclef ace_dvnamic_cached_anocatoi'ace_syncii_null_mutex allocator;allocator cache(1000, maxsize);void testcachedo int i = 0;for (i = 0; i 1000; i+) pi = cache, malloc(maxsize); assert (pi != null);
16、 for (i = 0; i 1000; i+) cache. free(pi);jtypedef acejlalloc ace_mmap_memory_pool, ace_synch_mutex malloc_mmap;typedef acejlalloc ace_local_memory_pool, ace_syncii_null_mutex malloc_local;tvpedef ace_malloc acejl0cal_mem0ry_p00l, ace_syncii_mutex mal1oc_local_mutex;typedef ace malloc ace shared memo
17、ry pool, ace synch mutex malloc share mutex;mbtypedef ace_malloc ace_sbrk_memory_pool, ace_syncii_mutex malloc_sbrk_mutex;tvpedef ace malloc ace lite mmap memory pool, ace synch mutex ma 11oc_mmap_1ite;template class t void testmalloc(t ml)int i 二 0;for (i = 0; i 1000; i卄)!pi = ml. malloc(maxsize);a
18、ssert(pi != null); for (i = 0; i 1000; i卄)ml.free(pi); pi = null;int main (int argc,char* argv) begin(10000)testmalloc();end( testmalloc ) begin(10000) testcachedo ;exd( testcached ) acemmapmemorypooloptionsoptions(ace_default_base_addr,acejw_memory_pool_0ptions:always_fixed, 1024 * 10000 );malloc_m
19、map nim( hello , hello , options);/fprintf (stderr, %d chuncks , ml. avail_chunks(maxsize); begin(10000)testmalloc(mm);end( tostmallocmmap )mm.remove(); malloc_mmap_lite mml ( helloq , helloq , options);/fprintf (stderr, %d chuncks , ml. avail_chunks(maxsize); begin(10000)testmalloc (mnil);end( test
20、mallocmmaplite )niml. remove () ; malloc local nil ( hellol/fprintf (stderr, %d chuncks , ml. ava訂_chunks(maxsize); begin(10000)testmalloc(ml);end( testmalloclocal )ml. remove(); malloc_local_mutex mlm( hello2/fprintf (stderr, %d chuncks , ml. avail chunks(maxsize);begin(10000)testmalloc(mlm);end( t
21、estmalloclocalmutex )mlm. remove(); malloc_local mlb( hellob/fprintf (stderr, %d chuncks , ml. avail chunks (maxsize); begin(10000)testmalloc(mlb);end( testmalloc_brk_mutex )mlb. remove ();ace_shared_memory_pool_0ptions options2(ace_default_base_addr, 1,ace default file perms, 1, 1024 * 1200 );mallo
22、c share mutex msm( hello3 , hello3 , options2);begin(10000)testmalloc(msm);end( testmallocsharemutex ) msm. remove();return 0;來自:/blog/cnsjf66d6083fd44cd13! 183. entrytestmalloc loop 10000 use time 32. 950000 s testcached loop 10000 use time 1. 730000 stestmallocmmap loop 10000 use time 5.050000 s t
23、estmallocnimaplite loop 10000 use time 5. 030000 s testmalloclocal loop 10000 use time 0. 620000 stestmalloclocalmutex loop 10000 use time 4.250000 s testmalloc_brk_mutex loop 10000 use time 0.600000 stestmallocsharemutex loop 10000 use time 4.360000 sttinclude ace/os ns stdio.hinclude ace/0s_ns_str
24、ing. h#include ace/malloc t. h#include ace/null_mutex. h ttinclude time, h include assert, h clock_t _begin;clock_t _end;int _loop;#define begin(n)begin = clock();for (_loop = 0; _loop _loop+) #define end(s) _end = clock ();printf ( %s loop %d use time %lf s , s, _loop , (double)(_end -_begin) / (do
25、uble)clocks_per_sec); const int maxsize = 1024;void *p1000;void testmalloc()iint i 二 0;for (i = 0; i 1000; i+) pi = malloc(maxsize); assert(pi != null); for (i = 0; i 1000; i卄)free(pi) ;itypedef char blockmaxsize;typedef ace_dynamic_cached_al1ocatorace synch null mutex allocator;allocator cache(1000
26、, maxsize);void testcached()int i = 0;for (i = 0; i 1000; i+) pi = cache, malloc(maxsize); assert (pi != null); for (i = 0; i 1000; i+) cache. free(pi);jtypedef acejlalloc ace_mmap_memory_pool, ace_syncii_mutex malloc_mmap;tvpedef ace malloc ace local memory pool, ace synch null mutex malloc local;t
27、ypedef ace malloc ace local memory pool, ace synch mutex malloc local mutex;tvpedef ace malloc ace shared memory pool, ace synch mutexmal1oc_share_mutex;tvpedef ace malloc ace sbrk memory pool, ace synch mutex malloc sbrk mutex;tvpedef ace malloc ace lite mmap memory pool, ace synch mutexmalloc mmap
28、lite;template class tvoid testmal1oc(t ml) int i = 0;for (i 二 0; i 1000; i*) pi = ml. malloc(maxsize); assert (pi != null);for (i = 0; i 1000; i卄)ml. free(pi); pi = null; int main(int argc, char* argv) begin(10000)testmalloc();end( testmalloc ) begin(10000)testcachedo ;end( testcached ) ace_mmap_mem
29、ory_pool_optionsoptions(ace_default_base_addr, ace_mmap_memory_pool_options:always_ftxed, 1024* 10000 );malloc mmap mm( hello , hello , options);/fprintf (stderr, %d chuncks , ml. avail chunks(maxsize); begin(10000)testmalloc(mm);end( testmallocmniap )mm. remove() ; malloc_mniap_lite mml ( helloq ,
30、helloq , options);/fprintf (stderr, %d chuncks , ml. avaii chunks(maxsi ze); beg in (10000)testmalloc(mml);exd( testmallocmniaplite )mml. remove(); mal1oc_local ml( hellol/fprintf(stderr, %d chuneks ,ml. avail_chunks(maxsize); begin(10000)testmalloc(ml);end( testmalloclocal )ml.remove(); mal1oc_loca
31、l_mutex mlm( hello2/fprintf (stderr, %d chuncks , ml. avai1 chunks(maxstze);begin(10000)testmalloc(mlm);exd( testmallociocalmutex )mlm. remove(); malloc local mlb( hellob/fprintf (stderr, %d chuncks , ml. avaii chunks(maxsize); beg in (10000)testmdlloc(mlb);end( testmalloc_brk_mutex )mlb. remove();a
32、ce shared memory pool optionsoptions2(ace_default_base_addr, 1,ace_default_ftle_perms, 1, 1024 * 1200 );mal1oc_share_mutex msm( hello3 , hello3 , options2);begin(10000)testmalloc(msm);end( testmalloesharemutex )msm. remove ();return 0;來自:/blog/cns!f66d6083fd44cd13! 183. entry testmalloc loop 10000 u
33、se time 32. 950000 stestcached 1oop 10000 use time 1. 730000 stestmallocmmap 1oop 10000 use time 5.050000 s testmallocmmap1ite loop 10000 use time 5. 030000 s testmalloclocal loop 10000 use time 0. 620000 stestmalloclocalmutex loop 10000 use time 4.250000 s testmalloc_brk_mutex loop 10000 use time 0
34、.600000 s testmallocsharemutcx loop 10000 use time 4.360000s#include ace/os_ns_stdio. h#include ace/0s_ns_string. h#inelude ace/malloc t. h#inelude ace/null mutex, h ttincludo time, h include assert, h clock t begin; clock_t _end;int _loop;define begin(n)_begin = clock();for (_loop = 0; _loop _loop+
35、) #define end(s) _end = clock ();printf ( %s loop %d use time %lf s , s, _loop , (double) (_end - _begin) / (double)clocks_per_sec); const int maxsize =1024;void *p1000; void testmal loc () int i = 0;for (i = 0; i 1000; i卄)pi = malloc(maxstze);assert(pi != null); for (i 二 0; i 1000; i*) free(pi); ty
36、pedef char blockmaxstze;typedef acedynamiccachedallocatorace_synch_nui丄_mutex al locator;allocator cache(1000, maxstze);voi d testcached()int i 二 0;for (i = 0; i 1000; i+) pi = cache, malloc(maxsize); assert (pi != null); for (i = 0; i 1000; i卄)cache. free(pi);tvpedef acejlalloc ace_mmap_memory_pool
37、, ace_syncii_mutex malloc_mniap;typedef ace malloc ace local memory pool, ace synch null mutex malloc local;tvpedef ace malloc ace local memory pool, ace synch mutexmallococal_mutex;typedef acejlalloc ace_shared_memory_pool, ace_synch_mutex mal1ocshare mutex;tvpedef ace malloc ace sbrk memory pool,
38、ace synch mutex malloc sbrk mutex;typedef acejlalloc ace_lite_mmap_memory_pool, ace_synch_mutexmalloc nimap lite;template class t void testmalloc(t ml)int i = 0;for (i 二 0; i 1000; i*) pi = ml. malloc(maxsize): assert (pi != null); for (i = 0; i 1000; i+) ml. free(pi); pi = null; int main(int argc,
39、char* argv) begin(10000)testmalloc();end( testmalloc ) begin(10000)testcachedo ;exd( testcached ) ace mmap memory pool options options (ace default base addr,ace_mmap_memory_pool_0ptions:always_ftxed, 1024 *10000 );malloc_mniap nim( hello , hello , options);/fprintf (stderr, %d chuncks , ml. avail_c
40、hunks(maxsize); begin(10000) testmalloc(mm);end( testmallocmmap )mm. remove (); malloc_mmap_lite mml ( helloq , helloq ,options);/fprintf (stderr, %d chuncks , ml. avail_chunks(maxsize); begin(10000) testmalloc(mml);end( testmallocmmaplite )mml> remove(); malloc_local ml( hellol/fprintf (stderr,
41、%d chuncks , ml. avail_chunks(maxsize);begin(10000) testmalloc(ml);end( tcstmalloclocal )ml. remove(); malloc local mutex mlm( hello2/fprintf (stderr, %d chuncks , ml. avail chunks (maxsize); begin(10000)testmalloc(mlm);end( testmalloclocalmutcx )mlm.removeo; malloc_local mlb( hellob/fprintf (stderr
42、, %d chuncks , ml. avail chunks (maxsize); begin(10000) testmalloc(mlb);end( testmallocbrkmutex )mlbromovo();ace shared memory pool optionsoptions2(ace default base addr, 1,ace default file perms, 1, 1024 * 1200 );malloc share mutex msm( hello3 , hello3 , options2); begin(10000)testmalloc(msm);end(
43、testmallocsharemutex )msm remove ();return 0;來自:/blog/cns!f66d6083fd44cd13! 183. entry testmalloc loop 10000 use time 32. 950000 s testcached loop 10000 use time 1. 730000 stestmallocmmap loop 10000 use time 5.050000 s testmallocmmaplito loop 10000 use time 5.030000 s testmalloclocal loop 10000 use
44、time 0.620000 stestmalloclocalmutex loop 10000 use time 4.250000 s testmalloc brk mutex loop 10000 use time 0. 600000 s testmallocsharemutex loop 10000 use time 4. 360000 sttinclude ace/0s_ns_stdio. h#include ace/0s_ns_string. h#include ace/malloc_t. h#inelude ace/null_mutex. h ttinclude time.h incl
45、ude assert, h clock_t _begin; clock t end;int _loop;#define begin(n) begin = clock();for (_loop = 0; _loop _loop+) #define end(s) _end = clock ();printf ( %s loop %d use time %lf s , s, _loop , (double) (_end - begin) / (double)clocks per sec); const int maxsize = 1024;void *p1000;void testmalloc()
46、int i = 0;for (i = 0; i 1000; i卄)pi = malloc(maxsize); assert(pi != null);for (i = 0; i 1000; i+) free(pi);typedef char blockmaxsize;!= null); ace_synch_mutex ma11oc_mmap;typedeface mallocace_l0cal_mem0ry_p00l,ace_syncii_null_mutex malloc_local;typedeface_mallocace_local_memory_pool,ace synch mutex
47、malloc local mutex;typedeface mallocace_siiared_mem0ry_p00l, ace_syncii_mutex malloc_share_mutex;typedeface mallocace_sbrk_memory_pool, ace.synciijfutex malloc_sbrk_mutex;typedef ace_dvnamic_cached_al1ocatorace_synch_null_mltex allocator;allocator cache (1000, maxstze);void testcached()int i 二 0;for (i = 0; i 1000; i+) pi = cache, malloc(maxsize); assert (pifor (i = 0; i 1000; i+) cache. free(pi) ;typedef
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 買賣種子合同范本
- 農(nóng)業(yè)委托種植合同范本
- 體育新城租房合同范本
- 剩余瓷磚售賣合同范本
- 人工包給勞務(wù)公司合同范本
- 協(xié)助出口退稅合同范本
- 農(nóng)資經(jīng)營聘用合同范本
- 3人共同合作合同范本
- lng承運合同范本
- 醫(yī)保專員勞動合同范本
- 2024年高考真題-政治(福建卷) 含解析
- 大模型技術(shù)深度賦能保險行業(yè)白皮書2024
- (蘇少版)綜合實踐一年級下冊第四單元電子教案
- 中國老年危重患者營養(yǎng)支持治療指南2023解讀課件
- 《光伏電站運行與維護》試題及答案一
- DBJ∕T 15-19-2020 建筑防水工程技術(shù)規(guī)程
- 二十四式太極拳教案高一上學(xué)期體育與健康人教版
- 2024-2025學(xué)年外研版(2024)七年級英語上冊英語各單元教學(xué)設(shè)計
- 國家病案質(zhì)控死亡病例自查表
- 一年級體育教案全冊(水平一)下冊
- 全身麻醉后護理常規(guī)
評論
0/150
提交評論