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
查看全文
相关阅读:
六:Vue之父子组件间的三种通信方式
五:Vue之ElementUI 表格Table与分页Pagination组件化
四:Vue之VUEX状态管理
三:Vue之混入(mixin)与全局混入
二:Vue之ElementUI Form表单校验
一:Vue之开发环境搭建
变了,说不出来的感觉。
20180320作业2:进行代码复审训练
20180320作业1:源代码管理工具调查
15软工课后作业02-15100120
原文地址:https://www.cnblogs.com/len3d/p/993698.html
最新文章
Python+selenium 下载安装
缺陷管理规范及流程
APP测试的要点
bug生命周期
浏览器兼容性知识和软件测试计划
测试用例的编写
软件测试需求分析
测试用例的设计方法
软件测试的生命周期及测试流程
软件测试的定义与分类
热门文章
兼容IE6定位底部
js密码加密
点击选择图片并返回上传
【转】jQuery插件的几种写法
mui点击按钮复制文本
js 数组 随机函数
DOM操作——怎样添加、移除、移动、复制、创建和查找节点。
DOM结构——两个节点之间可能存在哪些关系以及如何在节点之间任意移动
懒加载和预加载
七:Vue之适配test环境变量(2.0版)
Copyright © 2011-2022 走看看