實驗五? 內存管理實驗
一、實驗目的
1、了解操作系統動態分區存儲管理過程和方法。
2、掌握動態分區存儲管理的主要數據結構--空閑表區。
3、加深理解動態分區存儲管理中內存的分配和回收。
4、掌握空閑區表中空閑區3種不同放置策略的基本思想和實現過程。
5、通過模擬程序實現動態分區存儲管理。
6、了解請求分頁虛擬存儲管理技術的方法和特點。
7、通過模擬實現請求頁式存儲管理的幾種基本頁面置換算法。
8、掌握頁面置換算法種缺頁率、置換率和命中率的計算方法。
二、實驗內容
1、編程模擬實現動態分區管理中內存的分配和回收及空閑區表的管理。(2分)
首次適應算法(First Fit)參考程序:
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#define N 5
struct freearea
{
??? int startaddr;? //空閑區起始地址
??? int size;????? //空閑區大小
??? int state;???? //1表示空閑,0表示占用
}freeblock[N]={{20,20,1},{80,50,1},{150,100,1},{300,30,1},{600,100,1}};
int alloc(int size)
{
??? int i,tag=0,allocaddr;
??? for(i=0;i<N;i++)
??? {
??????? if(freeblock[i].state==1 && freeblock[i].size>size) //申請空間小于空閑空間
??????? {
?????????? allocaddr=freeblock[i].startaddr;?? //作業地址
?????????? freeblock[i].startaddr+=size;?? //新空閑區起始地址
?????????? freeblock[i].size-=size;?????? //新空閑區大小
?????????? tag=1;? //分配標記
?????????? break;
??????? }
??????? else if(freeblock[i].state==1 && freeblock[i].size==size)//申請空間正好等于空閑空間
??????? {
?????????? allocaddr=freeblock[i].startaddr;
?????????? freeblock[i].state=0;tag=1;
?????????? break;
??????? }
??? }
??? if(tag==0)? //表示沒找到合適的空閑區,未分配內存
??????? allocaddr=-1;
??? return allocaddr; //返回作業地址
}
void setfree(int addr,int size) //傳過來的參數是要釋放內存的起始地址和大小
{
??? int i,tag1=0,tag2=0,n1=0,n2=0;
??? for(i=0;i<N;i++)
??? {
??????? if(freeblock[i].startaddr+freeblock[i].size==addr && freeblock[i].state==1)
??????? {
?????????? tag1=1; ??? //有上鄰標記
?????????? n1=i;?? //記錄上鄰數組位置(分區號)
?????????? break;
??????? }
??? }
??? for(i=0;i<N;i++)
??? {
??????? if(freeblock[i].startaddr==addr+size && freeblock[i].state==1)?
??????? {
?????????? tag2=1;???? //有下鄰標記
?????????? n2=i;?? //記錄下鄰數組位置(分區號)
?????????? break;
??????? }
??? }??????
??? if(tag1==1 && tag2==0)? //有上鄰無下鄰
??? {
??????? freeblock[n1].size+=size;
??? }
??? else if(tag1==1 && tag2==1) //有上鄰有下鄰
??? {
?????????? freeblock[n1].size+=freeblock[n2].size+size;
?????????? freeblock[n2].state=0;//???
??? }
??? else if(tag1==0 && tag2==1) //無上鄰有下鄰
??? {
??????? freeblock[n2].startaddr=addr;
??????? freeblock[n2].size+=size;
??? }
??? else??? //無上鄰無下鄰(表明空間正好全部分配出去,空間的狀態為0)
??? {
??????? for(i=0;i<N;i++)
??????? {
?????????? if(freeblock[i].state==0)?? //通過空間狀態值找到這塊空間
?????????? {
?????????????? freeblock[i].startaddr=addr;
?????????????? freeblock[i].size=size;
?????????????? freeblock[i].state=1;
?????????????? break;
?????????? }
??????? }
??? }
}
void adjust()
{
??? int i,j;
??? struct freearea temp;
??? for(i=1;i<N;i++)??? //依據首次適應算法將空閑區按起始地址由低到高冒泡排序
??? {
??????? for(j=0;j<N-i;j++)
??????? {
?????????? if(freeblock[j].startaddr>freeblock[j+1].startaddr)
?????????? {
?????????????? temp=freeblock[j];
?????????????? freeblock[j]=freeblock[j+1];
?????????????? freeblock[j+1]=temp;
?????????? }
??????? }
??? }
??? for(i=1;i<N;i++)??? //把狀態為0的排到后面
??? {
??????? for(j=0;j<N-i;j++)
??????? {
?????????? if(freeblock[j].state==0 && freeblock[j+1].state==1)
?????????? {
?????????????? temp=freeblock[j];
?????????????? freeblock[j]=freeblock[j+1];
?????????????? freeblock[j+1]=temp;
?????????? }
??????? }
??? }
}
void print()
{
??? int i;
??? printf("\t|-------------------------------|\n");
??? printf("\t|startaddr??? size????? state |\n");
??? for(i=0;i<N;i++)
??? printf("\t|%4d???? %4d ? %4d |\n",freeblock[i].startaddr,freeblock[i].size,freeblock[i].state);???
}
int main()
{
??? int size,addr;
??? char c1,c2,c;
??? printf("At first the free memory is this:\n");//首先,空閑區是這樣的
??? adjust();
??? print();???
??? printf("Is there any job request memory?(y or n):");//有作業需要申請內存么?
??? while((c1=getchar())=='y')
??? {
??????? printf("Input request memory size:"); //輸入所需內存大小
??????? scanf("%d",&size);
??????? addr=alloc(size); //調用內存分配函數,返回的是作業的起始地址
??????? if(addr==-1)
?????????? printf("There is no fit memory.Please wait!!!\n");
??????? else
??????? {
?????????? printf("Job's memory start address is:%d\n",addr);??? //輸出作業的起始地址
?????????? printf("Job's size is:%d\n",size);? //輸出作業大小
?????????? printf("After allocation the free memory is this:\n");??? //分配后可用內存如下:???????? adjust();
?????????? print();
?????????? printf("Job is running.\n");
??????? }
??????? getchar();
??????? printf("Is there any memory for free?(y or n):");//有需要釋放的內存么?
??????? while((c2=getchar())=='y')
??????? {
?????????? printf("Input free area startaddress:");
?????????? scanf("%d",&addr);? //輸入要釋放內存的起始地址
?????????? printf("Input free area size:");
?????????? scanf("%d",&size);? //輸入要釋放內存的大小
?????????? setfree(addr,size); //調用釋放內存函數
?????????? adjust();
?????????? print();
?????????? getchar();
?????????? printf("Is there any memory for free?(y or n):");?? ???
??????? }
??????? getchar();
??????? printf("Is there any job request memory?(y or n):");
??? }
??? return 0;??
}
運行結果截屏(包含分配和回收兩部分):
分析該程序,列出各模塊實現的功能:
- alloc()
根據作業的大小申請空閑內存區域,并返回作業的起始地址。
2)setfree()
釋放指定起始地址和大小的內存區域,將其設置為空閑狀態。
3) adjust()
根據首次適應算法對空閑區進行排序和整理。
- 修改上題,用最佳適應算法和最壞適應算法模擬內存空間的分配和回收。(4分)
注:只需列出程序不同部分,無需將整個程序列出。
- 最佳適應算法
int best_fit_alloc(int size) {
??? int i, allocaddr = -1, min_size = INT_MAX;
??? for (i = 0; i < N; i++) {
??????? if (freeblock[i].state == 1 && freeblock[i].size >= size && freeblock[i].size < min_size) {
??????????? allocaddr = freeblock[i].startaddr;
??????????? min_size = freeblock[i].size;
??????? }
??? }
??? if (allocaddr != -1) {
??????? for (i = 0; i < N; i++) {
??????????? if (freeblock[i].startaddr == allocaddr) {
??????????????? if (freeblock[i].size > size) {
??????????????????? freeblock[i].startaddr += size;
??????????????????? freeblock[i].size -= size;
??????????????? } else {
??????????????????? freeblock[i].state = 0;
??????????????? }
??????????????? break;
??????????? }
??????? }
??? }
???
??? return allocaddr;
}
- 最壞適應算法
int worst_fit_alloc(int size) {
??? int i, allocaddr = -1, max_size = -1;
??? for (i = 0; i < N; i++) {
??????? if (freeblock[i].state == 1 && freeblock[i].size >= size && freeblock[i].size > max_size) {
??????????? allocaddr = freeblock[i].startaddr;
??????????? max_size = freeblock[i].size;
??????? }
??? }
??? if (allocaddr != -1) {
??????? for (i = 0; i < N; i++) {
??????????? if (freeblock[i].startaddr == allocaddr) {
??????????????? if (freeblock[i].size > size) {
??????????????????? freeblock[i].startaddr += size;
??????????????????? freeblock[i].size -= size;
??????????????? } else {
??????????????????? freeblock[i].state = 0;
??????????????? }
??????????????? break;
??????????? }
??????? }
??? }
???
??? return allocaddr;
}
- 編寫程序實現先進先出頁面置換算法,并計算缺頁次數,缺頁率,置換次數和命中率。(2分)
參考程序:
#include <stdio.h>
//初始化內存隊列
void initializeList(int list[],int number){
??? int i;
??? for (i = 0; i < number; i ++) {
??????? list[i] = -1;
??? }
}
//展示要訪問頁面號數組
void showList(int list[], int number){
??? int i;
??? for (i = 0; i < number; i ++) {
??????? printf("%2d",list[i]);
??? }
??? printf("\n");
}
//展示當前內存狀態
void showMemoryList(int list[],int phyBlockNum){
??? int i;
??? for (i = 0; i < phyBlockNum; i ++) {
??????? if (list[i] == -1) {
??????????? break;
??????? }
??????? printf(" |%d|",list[i]);
??? }
??? printf("\n");
}
//計算各項指標
void informationCount(int missingCount,int replaceCount,int pageNum){
??? printf("缺頁次數:%d?? 缺頁率:%d/%d\n",missingCount,missingCount,pageNum);
??? double result = (double)(pageNum - missingCount)/(double)pageNum;
??? printf("置換次數:%d? 命中率:%.2f\n",replaceCount,result);
}
//先進先出置換算法
void replacePageByFIFO(int memoryList[],int phyNum,int strList[],int pageNum){
??? //置換次數
??? int replaceCount = 0;
??? //缺頁次數
??? int missingCount = 0;
??? //記錄當前最早進入內存的下標
??? int pointer = 0;
??
//記錄當前頁面的訪問情況: 0 未訪問
int i,j,isVisited = 0;
??? for (i = 0; i < pageNum; i ++) {
??????? isVisited = 0;
??????? //判斷是否需要置換->內存已滿且需要訪問的頁面不在內存中
??????? for (j = 0; j < phyNum; j ++) {
??????????? if (memoryList[j] == strList[i]) {
??????????????? //該頁面已經存在內存中
??????????????? //修改訪問情況
??????????????? isVisited = 1;
??????????????? //展示
??????????????? printf("%d\n",strList[i]);
??????????????? break;
??????????? }
??????????? if (memoryList[j] == -1) {
??????????????? //頁面不在內存中且內存未滿->直接存入
??????????????? memoryList[j] = strList[i];
??????????????? //修改訪問情況
??????????????? isVisited = 1;
??????????????? missingCount ++;
??????????????? //展示
??????????????? printf("%d\n",strList[i]);
??????????????? showMemoryList(memoryList, phyNum);
??????????????? break;
??????????? }
??????? }
??????? if (!isVisited) {
??????????? //當前頁面還未被訪問過->需要進行頁面置換
??????????? //直接把這個頁面存到所記錄的下標中
??????????? memoryList[pointer] = strList[i];
??????????? //下標指向下一個
??????????? pointer ++;
??????????? //如果到了最后一個,將下標歸零
??????????? if (pointer > phyNum-1) {
??????????????? pointer = 0;
??????????? }??????????
??????????? missingCount ++;
??????????? replaceCount ++;
??????????? //展示
??????????? printf("%d\n",strList[i]);
??????????? showMemoryList(memoryList, phyNum);
??????? }
??? }
??? informationCount(missingCount, replaceCount, pageNum);//計算各項指標
}
int main(int argc, const char * argv[]) {?
//物理塊的數量
??? int phyBlockNum;
??? printf("請輸入物理塊數量:\n");
scanf("%d",&phyBlockNum);
??? //生成內存隊列數組
int memoryList[phyBlockNum];
??? //初始化內存狀態
??? initializeList(memoryList, phyBlockNum);
//showMemoryList(memoryList,phyBlockNum);
??? //頁面數量
??? int pageNum;
??? printf("請輸入要訪問的頁面總數:\n");
scanf("%d",&pageNum);
??? //保存頁面號數組
??? int pageNumStrList[pageNum];
??? int i;
//將要訪問的頁面號存入數組中
??? printf("請輸入要訪問的頁面號:\n");
??? for (i = 0; i < pageNum; i ++) {
??????? scanf("%d",&pageNumStrList[i]);
}
??? //顯示要訪問頁面號數組中內容
showList(pageNumStrList, pageNum);
??? int chose;
??? while (1) {
??????? printf("請選擇所需的置換算法:\n");
??????? printf("1.FIFO 2.退出\n");
??????? scanf("%d",&chose);
???????
??????? switch (chose) {
??????????? case 1:
//顯示要訪問頁面號數組中內容
??????????????? showList(pageNumStrList, pageNum);
//調用先進先出置換算法
??????????????? replacePageByFIFO(memoryList, phyBlockNum, pageNumStrList, pageNum);
??????????????? //重新初始化內存
??????????????? initializeList(memoryList , phyBlockNum);
??????????????? break;
??????????? default:
??????????????? return 0;
??????????????? break;
??????? }
??? }???
??? return 0;
}
編譯及執行過程以及結果截屏:
分析程序功能:
1.用戶輸入物理塊數量和要訪問的頁面總數。
2.用戶輸入要訪問的頁面號,將其存入一個數組中。
3.用戶選擇要使用的置換算法,目前只支持FIFO算法。
4.程序調用replacePageByFIFO函數來執行FIFO算法: a. 該函數通過遍歷頁面號數組,判斷頁面是否在內存中,如果在則不進行操作,如果不在則進行頁面置換。 b. 如果內存未滿,直接將頁面存入內存;如果內存已滿,將最早進入內存的頁面置換出去,并將新頁面存入內存。 c. 統計缺頁次數和置換次數,并展示當前內存狀態。
5.調用informationCount函數計算并展示各項指標,包括缺頁次數、缺頁率、置換次數和命中率。
6.重新初始化內存,回到步驟3,直到用戶選擇退出程序為止。
- 編程實現其它頁面置換算法(如最近最久未使用算法或最佳置換算法等),計算缺頁次數,缺頁率,置換次數和命中率。(1分)
#include <stdio.h>
#define MAX_PAGES 100
#define MAX_FRAMES 10
// 初始化頁面訪問序列
void initializePages(int pages[], int numPages) {
??? printf("請輸入頁面訪問序列(以-1結束):\n");
??? int i = 0;
??? do {
??????? scanf("%d", &pages[i]);
??????? i++;
??? } while (pages[i-1] != -1 && i < numPages);
}
// LRU算法
int lru(int pages[], int numPages, int numFrames) {
??? int frames[MAX_FRAMES] = {-1}; // 幀表
??? int lruCount[MAX_FRAMES] = {0}; // 記錄每個幀最后一次使用的時間
??? int numFaults = 0; // 缺頁次數
??? int numReplacements = 0; // 置換次數
??? int numHits = 0; // 命中次數
??? int time = 0; // 記錄時間
???
??? for (int i = 0; i < numPages; i++) {
??????? int page = pages[i];
??????? int j;
??????? for (j = 0; j < numFrames; j++) {
??????????? if (frames[j] == page) {
??????????????? numHits++;
??????????????? lruCount[j] = time;
??????????????? break;
??????????? }
??????? }
??????? if (j == numFrames) {
??????????? int lruIndex = 0;
??????????? for (int k = 1; k < numFrames; k++) {
??????????????? if (lruCount[k] < lruCount[lruIndex]) {
??????????????????? lruIndex = k;
??????????????? }
??????????? }
??????????? frames[lruIndex] = page;
??????????? lruCount[lruIndex] = time;
??????????? numFaults++;
??????????? numReplacements++;
??????? }
??????? time++;
??? }
???
??? printf("\nLRU算法結果:\n");
??? printf("缺頁次數:%d\n", numFaults);
??? printf("缺頁率:%f\n", (float)numFaults/numPages);
??? printf("置換次數:%d\n", numReplacements);
??? printf("命中率:%f\n\n", (float)numHits/numPages);
???
??? return numFaults;
}
// 最佳置換算法
int optimal(int pages[], int numPages, int numFrames) {
??? int frames[MAX_FRAMES] = {-1}; // 幀表
??? int numFaults = 0; // 缺頁次數
??? int numReplacements = 0; // 置換次數
??? int numHits = 0; // 命中次數
???
??? for (int i = 0; i < numPages; i++) {
??????? int page = pages[i];
??????? int j;
??????? for (j = 0; j < numFrames; j++) {
??????????? if (frames[j] == page) {
??????????????? numHits++;
??????????????? break;
??????????? }
??????? }
??????? if (j == numFrames) {
??????????? int replaceIndex = -1;
??????????? int found = 0;
??????????? for (int k = 0; k < numFrames; k++) {
??????????????? int m;
??????????????? for (m = i+1; m < numPages; m++) {
??????????????????? if (frames[k] == pages[m]) {
??????????????????????? found = 1;
??????????????????????? if (m > replaceIndex) {
??????????????????????????? replaceIndex = m;
??????????????????????? }
??????????????????????? break;
??????????????????? }
??????????????? }
??????????????? if (!found) {
??????????????????? replaceIndex = k;
??????????????????? break;
??????????????? }
??????????? }
??????????? frames[replaceIndex] = page;
??????????? numFaults++;
??????????? numReplacements++;
??????? }
??? }
???
??? printf("最佳置換算法結果:\n");
??? printf("缺頁次數:%d\n", numFaults);
??? printf("缺頁率:%f\n", (float)numFaults/numPages);
??? printf("置換次數:%d\n", numReplacements);
??? printf("命中率:%f\n\n", (float)numHits/numPages);
???
??? return numFaults;
}
int main() {
??? int pages[MAX_PAGES];
??? int numPages;
??? int numFrames;
???
??? printf("請輸入頁面數:");
??? scanf("%d", &numPages);
??? printf("請輸入幀數:");
??? scanf("%d", &numFrames);
???
??? initializePages(pages, numPages);
???
??? lru(pages, numPages, numFrames);
??? optimal(pages, numPages, numFrames);
???
??? return 0;
}
- 編程用動態分區鏈形式模擬動態分區管理中內存的分配和回收,采用3種算法(首次適應算法,最佳適應算法,最壞適應算法)實現。(附加題)
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 100
typedef struct Node {
??? int start;
??? int end;
??? int size;
??? int status; // 0表示未分配,1表示已分配
??? struct Node* next;
} Node;
Node* head = NULL;
// 初始化內存
void initMemory() {
??? head = (Node*)malloc(sizeof(Node));
??? head->start = 0;
??? head->end = MAX_SIZE;
??? head->size = MAX_SIZE;
??? head->status = 0;
??? head->next = NULL;
}
// 打印內存分配情況
void printMemory() {
??? Node* current = head;
??? while (current != NULL) {
??????? printf("[%d-%d] Size: %d ", current->start, current->end, current->size);
??????? if (current->status == 0) {
??????????? printf("Status: Free\n");
??????? } else {
??????????? printf("Status: Allocated\n");
??????? }
??????? current = current->next;
??? }
??? printf("\n");
}
// 首次適應算法分配內存
void* allocateFirstFit(int size) {
??? Node* current = head;
??? while (current != NULL) {
??????? if (current->status == 0 && current->size >= size) {
??????????? int remainingSize = current->size - size;
??????????? if (remainingSize > 0) {
??????????????? Node* newNode = (Node*)malloc(sizeof(Node));
??????????????? newNode->start = current->start;
??????????????? newNode->end = current->start + size;
??????????????? newNode->size = size;
??????????????? newNode->status = 1;
??????????????? newNode->next = current->next;
??????????????? current->start = newNode->end;
??????????????? current->size = remainingSize;
??????????????? current->next = newNode;
??????????? } else {
??????????????? current->status = 1;
??????????? }
??????????? return (void*)current->start;
??????? }
??????? current = current->next;
??? }
??? return NULL;
}
// 最佳適應算法分配內存
void* allocateBestFit(int size) {
??? Node* current = head;
??? Node* bestFitBlock = NULL;
??? int bestFitSize = MAX_SIZE + 1;
??? while (current != NULL) {
??????? if (current->status == 0 && current->size >= size && current->size < bestFitSize) {
??????????? bestFitBlock = current;
??????????? bestFitSize = current->size;
??????? }
??????? current = current->next;
??? }
??? if (bestFitBlock != NULL) {
??????? int remainingSize = bestFitBlock->size - size;
??????? if (remainingSize > 0) {
??????????? Node* newNode = (Node*)malloc(sizeof(Node));
??????????? newNode->start = bestFitBlock->start;
??????????? newNode->end = bestFitBlock->start + size;
??????????? newNode->size = size;
??????????? newNode->status = 1;
??????????? newNode->next = bestFitBlock->next;
??????????? bestFitBlock->start = newNode->end;
??????????? bestFitBlock->size = remainingSize;
??????????? bestFitBlock->next = newNode;
??????? } else {
??????????? bestFitBlock->status = 1;
??????? }
??????? return (void*)bestFitBlock->start;
??? }
??? return NULL;
}
// 最壞適應算法分配內存
void* allocateWorstFit(int size) {
??? Node* current = head;
??? Node* worstFitBlock = NULL;
??? int worstFitSize = -1;
??? while (current != NULL) {
??????? if (current->status == 0 && current->size >= size && current->size > worstFitSize) {
??????????? worstFitBlock = current;
??????????? worstFitSize = current->size;
??????? }
??????? current = current->next;
??? }
??? if (worstFitBlock != NULL) {
??????? int remainingSize = worstFitBlock->size - size;
??????? if (remainingSize > 0) {
??????????? Node* newNode = (Node*)malloc(sizeof(Node));
??????????? newNode->start = worstFitBlock->start;
??????????? newNode->end = worstFitBlock->start + size;
??????????? newNode->size = size;
??????????? newNode->status = 1;
??????????? newNode->next = worstFitBlock->next;
??????????? worstFitBlock->start = newNode->end;
??????????? worstFitBlock->size = remainingSize;
??????????? worstFitBlock->next = newNode;
??????? } else {
??????????? worstFitBlock->status = 1;
??????? }
??????? return (void*)worstFitBlock->start;
??? }
??? return NULL;
}
// 回收內存
void deallocate(void* addr) {
??? Node* current = head;
??? Node* prev = NULL;
??? while (current != NULL) {
??????? if (current->start == (int)addr) {
??????????? current->status = 0;
??????????? // 合并相鄰的空閑塊
??????????? if (prev != NULL && prev->status == 0) {
??????????????? prev->end = current->end;
??????????????? prev->size += current->size;
??????????????? prev->next = current->next;
??????????????? free(current);
??????????????? current = prev;
??????????? }
??????????? if (current->next != NULL && current->next->status == 0) {
??????????????? current->end = current->next->end;
??????????????? current->size += current->next->size;
??????????????? Node* temp = current->next->next;
??????????????? free(current->next);
??????????????? current->next = temp;
??????????? }
??????????? return;
??????? }
??????? prev = current;
??????? current = current->next;
??? }
}
int main() {
??? initMemory();
??? printMemory();
??? void* addr1 = allocateFirstFit(20);
??? printf("Allocated block: [0-20]\n");
??? printMemory();
??? void* addr2 = allocateBestFit(30);
??? printf("Allocated block: [20-50]\n");
??? printMemory();
??? void* addr3 = allocateWorstFit(40);
??? printf("Allocated block: [50-90]\n");
??? printMemory();
??? deallocate(addr2);
??? printf("Deallocated block: [20-50]\n");
??? printMemory();
??? deallocate(addr1);
??? printf("Deallocated block: [0-20]\n");
??? printMemory();
??? void* addr4 = allocateBestFit(70);
??? printf("Allocated block: [0-70]\n");
??? printMemory();
??? return 0;
}
三、實驗總結和體會(1分)
通過實際編寫程序實現內存分配與回收的算法,我更加理解了這些算法的原理和實現方式。其次,通過對比不同算法的性能,我能夠更加準確地選擇適合當前需求的算法。最后,我還學到了一些實際應用中的內存管理技巧和策略,為日后的工作打下了基礎。
在實驗過程中,我發現自己對于某些算法和概念的理解還不夠深入,需要進一步學習和加強。此外,我在實驗中遇到了一些問題,如編寫不完善的算法導致程序出錯等,這些問題提醒我需要加強對代碼質量和細節的把控。