一个测试ACE各种内存分配策略规划效率的程序
- 格式:docx
- 大小:99.48 KB
- 文档页数:31
一个测试ACE各种内存分配策略规划效率的程序
LG GROUP system office room 【LGA16H-LGYY-LGUA8Q8-LGA162】
一个测试ACE各种内存分配策略效率的程序
64位平台C/C++开发注意事项
在/en/l/上例出了28个在64位平台上使用C/C++开发的注意事项,对于进入64位时代的程序员应该去看看这28个事项,这些英文读物对于有C/C++功底的朋友读起来应该并不难,我估计大约20-30分钟可以精读完一篇(或者更快),下面是这28个注意事项的列表。相信对大家一点有帮助。 Lesson 01. What 64-bit systems are.
Lesson 02. S
testmalloc loop 10000 use time s
testcached loop 10000 use time s
testmallocmmap loop 10000 use time s
testmallocmmaplite loop 10000 use time s
testmalloclocal loop 10000 use time s
testmalloclocalmutex loop 10000 use time s
testmalloc_brk_mutex loop 10000 use time s
testmallocsharemutex loop 10000 use time
s#include ace/
#include ace/
#include ace/
#include ace/ #include
#include 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 *p[1000];
void testmalloc()
{
int i = 0;
for (i = 0; i 1000; i++)
{
p[i] = malloc(MAXSIZE);
assert(p[i] != NULL);
}
for (i = 0; i 1000; i++)
{
free(p[i]);
}
}typedef char BLOCK[MAXSIZE];
typedef ACE_Dynamic_Cached_Allocator
ACE_SYNCH_NULL_MUTEX Allocator;Allocator
cache(1000, MAXSIZE);
void testcached()
{
int i = 0;
for (i = 0; i 1000; i++)
{
p[i] = (MAXSIZE);
assert(p[i] != NULL);
}
for (i = 0; i 1000; i++)
{
(p[i]);
}
}typedef ACE_Malloc ACE_MMAP_MEMORY_POOL,
ACE_SYNCH_MUTEX malloc_mmap;
typedef ACE_Malloc ACE_LOCAL_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;
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++)
{
p[i] = (MAXSIZE);
assert(p[i] != NULL);
}
for (i = 0; i 1000; i++)
{
(p[i]);
p[i] = NULL;
}
}int main(int argc,char* argv[])
{ BEGIN(10000)
testmalloc();
END( testmalloc ) BEGIN(10000)
testcached();
END( testcached ) ACE_MMAP_Memory_Pool_Options
options(ACE_DEFAULT_BASE_ADDR,
ACE_MMAP_Memory_Pool_Options::ALWAYS_FIXED, 1024 *
10000 );
malloc_mmap mm( hello , hello , options);
//fprintf(stderr, %d chuncks , (MAXSIZE));
BEGIN(10000)
testmalloc(mm);
END( testmallocmmap )
(); malloc_mmap_lite mml( helloq , helloq ,
options);
//fprintf(stderr, %d chuncks , (MAXSIZE));
BEGIN(10000)
testmalloc(mml);
END( testmallocmmaplite )
(); malloc_local ml( hello1
//fprintf(stderr, %d chuncks , (MAXSIZE));
BEGIN(10000)
testmalloc(ml);
END( testmalloclocal )
(); malloc_local_mutex mlm( hello2
//fprintf(stderr, %d chuncks , (MAXSIZE));
BEGIN(10000)
testmalloc(mlm);
END( testmalloclocalmutex )
(); malloc_local mlb( hellob
//fprintf(stderr, %d chuncks , (MAXSIZE));
BEGIN(10000)
testmalloc(mlb);
END( testmalloc_brk_mutex )
();
ACE_Shared_Memory_Pool_Options
options2(ACE_DEFAULT_BASE_ADDR, 1,
ACE_DEFAULT_FILE_PERMS, 1, 1024 * 1200 );
malloc_share_mutex msm( hello3 , hello3 ,
options2);
BEGIN(10000)
testmalloc(msm);
END( testmallocsharemutex )
();
return 0;
}来自:/blog/cns!F66D6083FD44CD13!
testmalloc loop 10000 use time s
testcached loop 10000 use time s
testmallocmmap loop 10000 use time s
testmallocmmaplite loop 10000 use time s
testmalloclocal loop 10000 use time s
testmalloclocalmutex loop 10000 use time s
testmalloc_brk_mutex loop 10000 use time s
testmallocsharemutex loop 10000 use time
s#include ace/
#include ace/
#include ace/
#include ace/ #include
#include 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 *p[1000];
void testmalloc()
{
int i = 0;
for (i = 0; i 1000; i++)
{
p[i] = malloc(MAXSIZE);
assert(p[i] != NULL);
}
for (i = 0; i 1000; i++)
{
free(p[i]);
}
}typedef char BLOCK[MAXSIZE];