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
查看全文
相关阅读:
LeetCode Convert Sorted List to Binary Search Tree
LeetCode Convert Sorted Array to Binary Search Tree
LeetCode Restore IP Addresses
Linux-NoSQL之memcached
Linux-LAMP虚拟主机配置
Linux-Discuz安装LAMP
python-Django与Nginx整合gunicorn模块
python-Django与Apache整合wsgi模块
python-Django收集主机信息json格式
Linux-监控与安全运维之zabbix
原文地址:https://www.cnblogs.com/len3d/p/993698.html
最新文章
P1484 种树
P1801 黑匣子_NOI导刊2010提高(06)
P2574 XOR的艺术
13.Roman to Integer (HashTable)
9.Palindrome Number (INT)
编码方式
12. Integer to Roman (HashTable)
11.Container With Most Water (Array; Two-Pointers)
10.Regular Expression Matching (String; Back-Track,DP)
8.String to Integer (atoi) (INT; Overflow)
热门文章
7.Reverse Integer (INT; Overflow)
6.ZigZag Conversion(Graph, traverse)
5.Longest Palindromic Substring (String; DP, KMP)
LeetCode Sort Colors
LeetCode Jump Game II
LeetCode Jump Game
LeetCode N-Queens
LeetCode Count and Say
LeetCode Construct Binary Tree from Inorder and Postorder Traversal
LeetCode Construct Binary Tree from Preorder and Inorder Traversal
Copyright © 2011-2022 走看看