联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2025-05-30 10:57


Assignment #3: DEBUGGING TIPS

(Activate and run the Simple Test Routine built within the start-up codes)

Dear class,

In order to help the class debug the codes more accurately for Assignment #3, I have prepared a guide here for examining the results of calculations in a step-by-step manner.

The start-up codes have a built-in Simple Test Routine that can be activated for debugging purposes.  This will help simplify the analysis of your codes.

---------------------------------------------------------------------------

Firstly, it would be helpful in debugging your codes, if you could display the number of nodes created inside your Free List (also called Buddy List).

You could also display the base address and the size of each of the nodes in the Free List -  this will tell us if memory is correctly being segmented (when allocating) and coalesced (when freeing).

---------------------------------------------------------------------------

For debugging purposes, I have actually created a simple test routine (inside the start-up codes) that will make it easier.  

In order to activate this simple test, modify the auxiliary.h file to enable RUN_SIMPLE_TEST as follows:


Inside main.cpp, I have actually made a provision for this Simple Test already, it will automatically switch to using 512 bytes for the MEMORYSIZE.



Next, given 512 bytes,  this Simple Test will execute the following sequence of memory allocation and deallocation requests:

malloc(13), malloc(3), malloc(110), free(3), free(13)

//-- this is due to my codes:

 char actions[] =      {'m' ,  'm', 'm', 'f', 'f'};  //m = MALLOC, f = FREE

int requests[] =      {13, 3, 110, 3, 13};  

//---

Set the Free List to have 4 rows, so that we can easily trace what the Buddy System is doing:

k Size(bytes)

3 512

2 256

1 128

0 64


In this example, we assume that the sizeof(Node) is 32 and the MINBLOCKSIZE is 64.


To debug, I suggest that you display the number of Nodes created in your FreeList.  I am providing (see diagrams below) a break-down of what the Buddy System should do with the Free List/Buddy List  (Note that the addresses are all relative):


malloc(13) should cause the Buddy System to create the following Nodes inside Free List:


As can be seen in the diagram (look for the Graphical View header), malloc(13) should cause the Buddy System to create 3 Nodes in the Free List: one of size 256 ( minus the Node size), another of size 128 (minus the Node size) and lastly, a node of size 64  ( minus the Node size).  The allocated block is of size 64 and is returned to the user.

In this example, the address of wholememory was set to 0, but in practice it will be some big number assigned by the VirtualAlloc() function (e.g. 0x24301a50000).


To get a better understanding of the details shown in the Excel worksheet, the following is a graphical view (showing the doubly-linked list) of the same FreeList.


The address of block (marked in red) is returned by malloc() to the requesting process.


Consequently, the allocated block is then removed from the Free List, as that block is no longer free.


Next, Malloc(3) should cause the Buddy System to create the following Nodes inside Free List:

Note: The blocks marked in red are no longer part of the FreeList, as they have been allocated already.    


To get a better understanding of the details shown in the Excel worksheet, the following is a graphical view (showing the doubly-linked list) of the same FreeList.

malloc(3) would cause the address of block (marked in red) to be assigned to the requesting process.


Next, Malloc(110) should cause the Buddy System to create the following Nodes inside Free List:

Note: The blocks marked in red are no longer part of the FreeList, as they have been allocated already.    



To get a better understanding of the details shown in the Excel worksheet, the following is a graphical view (showing the doubly-linked list) of the same FreeList.

malloc(110) would cause the address of block (marked in red) to be assigned to the requesting process.


Next, Free(3) should cause the Buddy System to create the following Nodes inside Free List.  We are interested in seeing how free blocks are coalesced:

Note: The blocks marked in red are no longer part of the FreeList, as they have been allocated already.    


Lastly, Free(13) should cause the Buddy System to create the following Nodes inside Free List:

Note: The blocks marked in red are no longer part of the FreeList, as they have been allocated already.    


I hope this helps.

Cheers,

Napoleon

相关文章

【上一篇】:到头了
【下一篇】:没有了

版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp