perating Systems and Networks cs159342

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 .    
iuww520 iuww520 iuww520 iuww520 iuww520 iuww520 iuww520 iuww520
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 << " \t Pick random size to allocate: " << size << endl;
#endif
n[k] = ( unsigned char * ) MALLOC (size); // do the allocation
if (n[k] != NULL ){
#ifdef DEBUG_MODE
cout << " \t allocated 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 << " \t Failed to allocate memory of size: " << size << endl;
}
}
#endif
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值