首页 > 其他分享 >159.342 操作系统和网络

159.342 操作系统和网络

时间:2023-06-04 12:56:49浏览次数:28  
标签:malloc codes 操作系统 implementation 网络 free memory your 159.342


159.342 - Operating Systems and Networks
Assignment #3 (due on 11/Jun)
Memory Management Using the Buddy System Strategy
OBJECTIVE:
The main objective in this assignment is to implement the Buddy System memory
management strategy by writing two functions that implement the same functionalities as
the C Standard library’s malloc() and free(). You should apply your knowledge of memory
management concepts, so the functions are as efficient as possible. The buddy system will
be characterised and compared against the existing C Standard library functions based on
ACTUAL RUNNING TIME and MEMORY USAGE. Given a large block of contiguous memory to manage, your functions should be able to fulfil
a series of memory allocation and deallocation requests. In your implementation, you are
not allowed to use the built-in malloc, free, new, delete or any other memory allocators that
come from other third-party libraries. START-UP CODES:
The start-up codes provide a test routine that makes successive calls for memory
allocations and deallocations, involving a replaceable implementation of MALLOC and
FREE. Functions for measuring the actual running time and total memory usage of the
memory management strategy are also provided.
///////////////////////////////
// TEST ROUTINE
///////////////////////////////
#ifdef RUN_COMPLETE_TEST
cout << "\n\n executing " << NO_OF_ITERATIONS << " rounds of combinations of memory allocation and deallocation..." <<
endl;
for(i=0;i<NO_OF_ITERATIONS;i++) {
k=myrand() % NO_OF_POINTERS; // pick a pointer
if(n[k]) { // if it was allocated then free it
// check that the stuff we wrote has not changed
if ( (n[k][0]) != (unsigned char) k)//(n[k]+s[k]+k) )
printf("Error when checking first byte! in block %d \n",k);
if(s[k]>1 && (n[k][s[k]-1])!=(unsigned char) k )//(n[k]-s[k]-k))
printf("Error when checking last byte! in block %d \n",k);
FREE(n[k]);
}size=randomsize(); // pick a random size
#ifdef DEBUG_MODE
cout << "\tPick random size to allocate: " << size << endl;
#endif n[k]=(unsigned char *)MALLOC(size); // do the allocation
if(n[k] != NULL){
#ifdef DEBUG_MODE
cout << "\tallocated memory of size: " << size << endl;
#endif s[k]=size; // remember the size
n[k][0]=(unsigned char) k; // put some data in the first and
if(s[k]>1) n[k][s[k]-1]=(unsigned char) k; // last byte
} else { cout << "\tFailed to allocate memory of size: " << size << endl;
}
}
#endif
You can switch between different memory management strategies by changing the
definition of MALLOC and FREE, as defined inside main.cpp (see below). The first two
options are already provided, but the third option corresponds to the Buddy System and
therefore, needs to be implemented in this assignment:
//---------------------------------------
// WHICH MEMORY MANAGEMENT STRATEGY?
//---------------------------------------
// enable the following compiler directives to test the real malloc and free
//(1) use built-in C functions
const string strategy = "malloc";
#define MALLOC malloc #define FREE free
//---------------------------------------
//enable the following compiler directives to test a simple implementation of malloc and free
//(2) use user-defined functions
//const string strategy = "mymalloc";
// #define MALLOC mymalloc
// #define FREE myfree
//---------------------------------------
//enable the following compiler directives to test your implementation of the Buddy system strategy
//(3) use Buddy System
// const string strategy = "Buddy System";
// #define USE_BUDDY_SYSTEM
// #define MALLOC buddyMalloc
// #define FREE buddyFree
//--------------------------------------- CORE FUNCTIONS REQUIRED:
Skeleton functions for buddy system’s malloc and free are already provided inside
buddysys.cpp. Write your implementation inside them. You are allowed to add any
supporting functions, data structures and variables in the program. void *buddyMalloc(int request_memory){
//write your buddy system’s memory allocation codes here
//this function should provide the same functionality as the malloc() function
}
int buddyFree(void *p){
//write your buddy system’s memory deallocation codes here
//this function should provide the same functionality as the free() function
}
AUXILIARY FUNCTIONS PROVIDED:
The Auxiliary functions, constants and data structures declared and implemented inside
auxiliary.cpp and auxiliary.h should all be kept as is. MINIMUM CONTIGUOUS MEMORY SIZE
As part of characterising the performance of your implementation, find the minimum
contiguous memory size that allows the Buddy System strategy to accommodate the
succession of memory allocation and deallocation requests in the test routine. To
accomplish this, you need to experiment with different settings for the NUMBEROFPAGES
until the test routine could be fully completed. Example:
As an example, if you set NUMBEROFPAGES equal to 1024, then the MEMORYSIZE could
be computed as follows:
// inside main.cpp
MEMORYSIZE = (long long int) ((long long int)NUMBEROFPAGES * (long long int)PAGESIZE);
Note that in the start-up codes, the PAGESIZE is set to 4096. Therefore, MEMORYSIZE will
be equal to 4,194,304 bytes (1024 * 4096) or 4.19 MegaBytes. Next, with your MEMORYSIZE setting, run the test routines to see if all requests for memory
allocations and deallocations can be satisfied. If not, increase the MEMORYSIZE. Table 1. MEASURE OF PERFORMANCE
Characterise your Buddy System’s implementation and compare it against the C Standard
library’s malloc and free by filling-up the following table. BUDDY SYSTEM STRATEGY
Characteristic Unit
MINIMUM
NUMBEROFPAGES
Pages
MINIMUM MEMORY SIZE MegaBytes
RUNNING TIME MicroSeconds
C Standard Library’s malloc and free
Characteristic Unit
MINIMUM
NUMBEROFPAGES
Pages
MINIMUM MEMORY SIZE MegaBytes
RUNNING TIME MicroSeconds
Other Notes
0 – zip all the files comprising your codes by compressing the entire folder. The structure of the folder and
subfolders should be exactly the same as that of the start-up codes given. 1 - Submit your files electronically via Stream. You should submit the complete set of files, required to
compile your codes, including the makefile, Measure of Performance (Table 1) Checklist (see Table 2)
and snapshots of simulation results. Bundle all your files together in a *.zip file. 2 - This assignment is worth 15 marks. 3 - Marks will be subtracted for obvious copying and/or for delays without justification.
Table 2. Checklist/Other technical details
Please accomplish the following check list in order to allow for accurate marking of your
assignment.
Item your assignment details Comments
1 Names and ID numbers of
Group Members
(maximum of 3 members in
a group)
2
Operating System(s) used
for testing your codes
Note that your programs
should run correctly under
Windows 10. 3 Compiler used Note that g++ 12.2.0 is
required
4
IDE used (e.g. SublimeText 3, ScITE)
5
Files: Have you submitted
all the files required to
compile your codes and
test it? Include the
makefile, source codes and
other support files:
/CMakeLists.txt, *.cpp, *.h, *.sln, .vcxproj, etc.
Yes/No Indicate ‘Yes’ or ‘No’. Make sure that you submit
all the supporting files if
you developed your codes
using CLion or Visual
Studio. The makefile
should suffice to build your
codes. 6
Required Functions Function
name
Indicate implementation level Indicate ‘full’, if you have
successfully completed
and tested the required
functionality, ‘partial’, if
you are only submitting a
partial implementation, or
‘none’, if not
accomplished. buddyMallo
c
buddyFree
7
Snapshot of simulation
results Yes/No
indicate ‘Yes’ or ‘No’, if
you have submitted the
required snapshot.
8
Number of iterations
successfully run using
RUN_COMPLETE_TEST, USE_SIMULATION_2
Specify what problems
occurred if the program
was not able to complete
the simulation. 9
If your implementation
cannot complete
RUN_COMPLETE_TEST, can it run on
RUN_SIMPLE_TEST?
Yes/No
Note: This setting can be
changed inside auxiliary.h

 

标签:malloc,codes,操作系统,implementation,网络,free,memory,your,159.342
From: https://www.cnblogs.com/simpleyfc/p/17455533.html

相关文章

  • Linux操作系统安装及服务控制
    Linux操作系统安装及服务控制一、设置Linux操作系统每次开机后自动进入字符模式界面。二、使用ntsysv工具同时调整2,3,4,5运行级别中的服务状态,关闭下列服务:atd,bluetooth,mdmonitor,rhnsd,rpcgssd,postfix.关闭下列服务:atd,bluetooth,mdmonitor,rhnsd,rpcgssd,postfix.atdbluetoothmdmo......
  • 网络支付海量数据存取处理的研究
    摘要:随着网络购物的普及,网上支付业务蓬勃发展,同时网络支付行为带来的海量数据处理也给网络支付平台带来了巨大挑战。本文从针对网络支付带来的海量数据带来的问题,通过改进和优化数据库配置、数据分割、数据分类、处理算法、数据访问、虚拟内存和文本格式处理等方面,对网络支付带来的......
  • LIux操作系统及Liux的发行版本
    一:概述    Liux操作系统是复杂的,它由Liux内核、程序库和用户程序接口组成。系统的底层由硬件和Liux内核进行交互的,用户程序接口通过调用程序库来请求内核服务。初学者肯定对其中的一些名词不太理解。下面对这些名词进行介绍。Liux内核:这是Liux系统的核心,它提供OS最基本的功......
  • 论文感谢 2023年3月21日,作于余杭塘河右岸杭州师范大学 信息学院网络空间安全专业应届
    致谢春天已经过去,夏天将要到来,今夜下了很大的雨,青蛙聒噪的叫个不停。我合上论文草稿,打开窗户回忆过去。三年过去了,我却没有很大的成就;一千个日夜的追寻,却也渐渐领悟了科研的真谛。过去种种焦虑焦灼都让我眉头紧锁,所有的开心快乐也都浮上心头。回忆浮现眼前,就像昨天发生的一样,此时......
  • 使用 HTTP Boot,可以批量部署操作系统和软件,提高管理效率和降低成本。下面是常用的几种
    使用HTTPBoot,可以批量部署操作系统和软件,提高管理效率和降低成本。下面是常用的几种批量部署方案:使用WindowsDeploymentServices(WDS):WDS是一种基于微软技术的网络引导服务,可以快速部署Windows操作系统和应用程序。通过配置WDS服务器和映像文件,可以实现从远程服务器引......
  • PXE(Preboot eXecution Environment)是一种通过网络引导计算机的协议,可以在没有本地存储
    PXE(PrebooteXecutionEnvironment)是一种通过网络引导计算机的协议,可以在没有本地存储设备或可启动介质的情况下从网络上加载操作系统和应用程序。PXE版本因厂商或标准制定者的不同而有所不同。以下是常见的PXE版本及其大致年代:PXE1.0:最早的PXE版本,于1999年左右推出。PXE2......
  • 微控制器实时操作系统实践1实时系统介绍
    0书籍简介这本实践指南将为你提供最重要的功能知识,以使实时操作系统(RTOS)在微控制器(MCU)上启动和运行。如果你有兴趣学习如何通过使用实际硬件的实例来实现RTOS的应用,并讨论常见的性能与开发时间的权衡,那么你就来对地方了!我们将使用自由RTOS来实现代码!我们将使用FreeRTOS内核实现......
  • HTTP Boot(即基于HTTP的引导)是一种网络引导协议,它使用HTTP作为文件传输协议,支持远程引
    HTTPBoot(即基于HTTP的引导)是一种网络引导协议,它使用HTTP作为文件传输协议,支持远程引导、安装和部署操作系统和应用程序。与传统的PXE(PrebooteXecutionEnvironment)方式相比,HTTPBoot具有更高的灵活性、可扩展性和安全性。HTTPBoot可以通过以下步骤实现:启动计算机后,BIOS会向......
  • 基础网络速查速会
    五层网络模型TCP/IPHTTPPostManAJAX浏览器的跨域问题JWTCOOKIESESSION文件上传文件下载缓存协议CSRFXSS网络性能优化分片传输域名和DNSSSL/TLS/HTTPSHTTP2WebSocket......
  • 2023年第三届陕西省大学生网络安全技能大赛本科高校组
    Crypto奇怪的sar第一步常规的lcg算法n1=137670797028117726329534659376416493367957852768263083700434198723955223922183386928456013703791817601151754417828367188186912209697081337658512940425529211281290630976671911327606706953154608427885071841566358882014......