zoukankan
html css js c++ java
a simple test of MemMan
#include
"
stdafx.h
"
#include
"
memman3_def.h
"
using
namespace
std;
class
Page
{
//
16
public
:
int
author;
int
date;
int
title;
int
text;
}
;
class
Wiki :
public
mem::resource
{
public
:
Wiki() : mem::resource(
2
)
{
}
bool
stream_in()
{
if
(
!
pages )
{
allocate( num );
return
true
;
}
return
false
;
}
mem::size_type stream_size()
{
if
( pages )
return
sizeof
(Page)
*
num;
else
return
0
;
}
void
*
stream_out()
{
void
*
ptr
=
(
void
*
) pages;
pages
=
NULL;
return
ptr;
}
void
allocate(
int
size )
{
num
=
size;
pages
=
(Page
*
) alloc(
sizeof
(Page)
*
num );
}
void
access_resource()
{
stream_begin();
/**/
//////
/ DO YOUR ACCESS HERE!
//////
/
////////////////////////////////////
stream_end();
}
void
deallocate()
{
dealloc( pages,
sizeof
(Page)
*
num );
}
public
:
Page
*
pages;
int
num;
}
;
const
int
access_size
=
100000000
;
const
int
test_size
=
100000
;
const
int
alloc_size
=
1000
;
const
int
heap_size
=
500000000
;
int
randnum(
int
size )
{
return
max(
int
(((
float
)rand()
/
(
float
)RAND_MAX)
*
(
float
)size),
1
);
}
int
_tmain(
int
argc, _TCHAR
*
argv[])
{
Wiki
*
wiki;
memman.begin( heap_size );
wiki
=
new
(memman.alloc(
sizeof
(Wiki)
*
test_size )) Wiki [test_size];
for
(
int
i
=
0
;i
<
test_size;
++
i)
wiki[i].allocate( randnum( alloc_size ) );
for
(
int
i
=
0
; i
<
access_size;
++
i )
{
int
index
=
randnum( test_size );
if
( index
>=
0
&&
index
<
test_size )
wiki[ index ].access_resource();
}
memman.print();
for
(
int
i
=
test_size
-
1
;i
>=
0
;
--
i)
wiki[i].deallocate();
memman.dealloc( wiki,
sizeof
(Wiki)
*
test_size );
memman.end();
int
a;
cin
>>
a;
return
0
;
}
heap allocated size: 476.837 MB
page size: 524288 Byte
cache allocated size: 880.509 MB
number of cache lookups: 100000000
cache hit rate: 99.9854 %
run time: 1 minutes 27 seconds
查看全文
相关阅读:
如何提取一个转录本的3'UTR区域的序列
如何研究某个gene的ceRNA 网络
ceRNA 调控机制
利用circpedia 数据库探究circRNA的可变剪切
R语言低级绘图函数-symbols
R语言低级绘图函数-grid
R语言低级绘图函数-axis
R语言低级绘图函数-title
R语言低级绘图函数-points
二叉树和二叉查找树之间的区别
原文地址:https://www.cnblogs.com/len3d/p/993698.html
最新文章
工作流JBPM_day01:1-说明_MyProcessDesigner_流程设计器
JBPM4.4_工作流基础_准备jBPM4.4环境
分页技巧__在项目中使用QueryHelper辅助对象实现分页效果
分页技巧_测试并继续改进分页用的QueryHelper辅助对象
分页技巧__设计分页用的QueryHelper辅助对象
分页技巧_改进JSP页面中的公共分页代码_实现分页时可以有自定义的过滤与排序条件
分页技巧_抽取出公共的分页用的Service方法
分页技巧__实现第二个分页(主题列表中的分页)并抽取部分重复的代码
分页技巧_实现第一个分页功能(回复列表中的分页)
分页技巧_分析分页的实现步骤_分析页面中显示的分页信息
热门文章
分页技巧__导入准备好的演示数据
论坛模块__发帖时使用FCKeditor
论坛模块_实现功能_分析与解决主题列表的排序问题_实现显示主题与发表回帖功能
论坛模块_实现功能3_分析与实现发表新帖的功能
论坛模块_实现功能2_实现显示版块列表与显示单个版块的功能
论坛模块_实现功能1_写基本代码
Spring_day04--HibernateTemplate介绍_整合其他方式_Spring分模块开发
Spring_day04--SSH框架整合过程
Spring_day04--Spring框架整合hibernate框架
par函数的adj 参数- 控制文字的对齐方式
Copyright © 2011-2022 走看看