




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、一个测试ace各种内存分配策略效率的程序个测试ace各种内存分配策略效率的程64位平台c/c+开发注意事项在/en/1/上例出了 28个在64位平台上使川c/c+开发的注意事项,对于进入64位时代 的程序员应该去看看这28个事项,这些英文读物对于冇c/c+功底的朋友读起來应该并不 难,我估计大约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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中班健康活动教案课件
- 多物种拟态协同进化-洞察及研究
- 2025版合伙人共享资源合作协议书
- 二零二五年KTV消防安全设备维护与检测合同
- 2025HSE安全培训与咨询服务协议范本
- 二零二五年度XX城市污水处理厂运营维护服务合同
- 2025年度物流配送中心运营管理合同
- 中班健康送礼物课件
- 初三语文备考试题及答案
- 郴州驾照考试题目及答案
- DGJ08-81-2015 现有建筑抗震鉴定与加固规程
- 房屋租赁合同范本15篇
- 2025至2030年中国飞行控制器行业市场供需态势及未来趋势研判报告
- 2025年汽车维修工职业资格考试试卷及答案
- 安全B证题库-安全生产知识考试用书
- 2025至2030年中国锦氨纶汗布市场分析及竞争策略研究报告
- 2024年江苏地质局所属事业单位招聘考试真题
- 2025年湖北省中考物理试题(含答案及解析)
- 几何画板 培训课件
- 2025年中小学暑假安全教育主题家长会 课件
- 经皮肺动脉瓣置换术(TPVRPPVI)
评论
0/150
提交评论