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
查看全文
相关阅读:
在上传文件时限制上传文件的大小,并捕捉超过文件大小限制的
javascript 获取标签具体位置
终端服务器超出了最大允许连接数
常用SQL语句书写技巧
Javascript实现截图功能(代码)
JavaScript实现类,有多种方法。
DBCC CHECKDB 数据库或表修复
Lucene的例子
控制同一exe程序打开多次
IIS6 MMC检测到此管理单元发生一个错误,建议您关闭并重新启动mmc
原文地址:https://www.cnblogs.com/len3d/p/993698.html
最新文章
springboot2.5.0 整合 redis 配置详解
Docker入门 第二课 镜像构建,Dockerfile解读
silverlight(二)样式
Ajax(一)显示可用内存空间
我的随想
silverlight(一)布局
javascript(一)计算器代码生成
C#使用sharp7实现对西门子Smart200PLC读写
用C#对ADO.NET数据库完成简单操作
SQL初级创建表和约束
热门文章
ListView 事件请参阅
C#抽象类可以有构造方法吗,若是有如何实现及调用?
C#操作MySQL数据库的简单例子(转)
VC++大杂烩
listview和datagirdview对mssql数据库的增删改查操作演示
c# winform DatagridView使用总结
C#中构造方法重载的相互调用
C#方法重载概念
扫二维码或http请求,url中+号被替换成空格
SQLSERVER 自增ID插入指定数据 与 获取表的下一个自增ID
Copyright © 2011-2022 走看看