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
查看全文
相关阅读:
Linux用户、用户组、文件权限设置
spring,springMvc和mybatis整合配置
spring,springMvc和hibernate整合
spring与mybatis
spring与Dbcp
初识事物
spring与Aop
初识spring
mysql 完整性约束
mysql数据库的基本操作
原文地址:https://www.cnblogs.com/len3d/p/993698.html
最新文章
ubuntu同步Centos7的chrony
centos安装向日葵远程错误
(iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 13306 -j DNAT --to-destination 172.18.0.2:3306
树莓派小机器raspberrypi的frp代理
sed正则中使用变量问题
Cannot delete or update a parent row: a foreign key constraint fails (`smartv2_2`.`sys_user_role_`,
mysql容器里不能识别中文输入
ERROR 1449 (HY000): The user specified as a definer ('skip-grants user'@'skip-grants host') does not exist
(Problem 73)Counting fractions in a range
(Problem 42)Coded triangle numbers
热门文章
(Problem 41)Pandigital prime
(Problem 70)Totient permutation
(Problem 74)Digit factorial chains
(Problem 46)Goldbach's other conjecture
(Problem 62)Cubic permutations(待续)
(Problem 72)Counting fractions
(Problem 53)Combinatoric selections
(Problem 49)Prime permutations
excel导入通用代码
文件上传下载
Copyright © 2011-2022 走看看