#include <bits/stdc++.h>
# include <graphics.h>
#include <tchar.h>
using namespace std;
int main(){
boxm[10].text = _T("hello");
return 0;
}
怎么办,崩溃!
#include <bits/stdc++.h>
# include <graphics.h>
#include <tchar.h>
using namespace std;
int main(){
boxm[10].text = _T("hello");
return 0;
}
怎么办,崩溃!
【相关推荐】
#include<stdio.h>
#include<stdlib.h>
struct nodespace{
int teskid; // 作业号
int begin; // 开始地址
int size; // 大小
int status; // 状态 0代表占用,1代表空闲
struct nodespace *next; // 后指针
};
void initNode(struct nodespace *p){
if(p == NULL){ //如果为空则新创建一个
p = (struct nodespace*)malloc(sizeof(struct nodespace));
}
p->teskid = -1;
p->begin = 0;
p->size = 640;
p->status = 1;
p->next =NULL;
}
void myMalloc1(int teskid,int size,struct nodespace *node){
while(node != NULL){
if(node->status == 1){ //空闲的空间
if(node->size > size){ //当需求小于剩余空间充足的情况
//分配后剩余的空间
struct nodespace *p = (struct nodespace*)malloc(sizeof(struct nodespace));
p->begin = node->begin + size;
p->size = node->size - size;
p->status = 1;
p->teskid = -1;
//分配的空间
node->teskid = teskid;
node->size = size;
node->status = 0;
//改变节点的连接
p->next = node->next;
node->next = p;
printf("==================================分配内存成功!==================================\n");
break;
}else if(node->size == size){ //需求空间和空闲空间大小相等时
node->teskid = teskid;
node->size = size;
node->status = 0;
printf("==================================分配内存成功!==================================\n");
break;
}
}
if(node->next == NULL){
printf("===============================分配失败,没有足够的空间!=============================\n");
break;
}
node = node->next;
}
}
void myFree(int teskid,struct nodespace *node){
if(node->next == NULL && node->teskid == -1){
printf("================================您还没有分配任何作业!================================\n");
}
while(node != NULL){
if(node->status == 1 && node->next->status ==0 && node->next->teskid == teskid){
struct nodespace *q = node->next;
node->next = node->next->next;
free(q);
printf("==================================释放内存成功!==================================\n");
if(node->next->status == 1){ //下一个空间是空闲空间时
node->size = node->size + node->next->size;
struct nodespace *q = node->next;
node->next = node->next->next;
free(q);
printf("==================================释放内存成功!==================================\n");
}
break;
}else if(node->status == 0 && node->teskid == teskid){ //释放空间和空闲空间不连续时
node->status = 1;
node->teskid = -1;
if(node->next != NULL && node->next->status == 1){ //下一个空间是空闲空间时
node->size = node->size + node->next->size;
struct nodespace *q = node->next;
node->next = node->next->next;
free(q);
}
printf("==================================释放内存成功!==================================\n");
break;
}else if(node->next == NULL){ //作业号不匹配时
printf("==================================没有此作业!!==================================\n");
break;
}
node = node->next;
}
}
void printNode(struct nodespace *node){
printf(" 内存情况 \n");
printf(" -------------------------------------------------------\n");
printf("| 起始地址\t结束地址\t大小\t状态\t作业号\t|\n");
while(node != NULL){
if(node->status==1){
printf("| %d\t\t%d\t\t%dKB\tfree\t 无\t|\n", node->begin + 1, node->begin+node->size, node->size);
}else{
printf("| %d\t\t%d\t\t%dKB\tbusy\t %d\t|\n", node->begin + 1, node->begin+node->size, node->size, node->teskid);
}
node = node->next;
}
printf(" -------------------------------------------------------\n");
}
void destory(struct nodespace *node){
struct nodespace *q = node;
while(node != NULL){
node = node->next;
free(q);
q = node;
}
}
void menu(){
printf("\n");
printf("\t\t\t\t ╭═════════════════════════════════○●○●═══╮\n");
printf("\t\t\t\t │ 首次适应算法的动态分区分配方式模拟 │\n");
printf("\t\t\t\t ╰═══○●○●═════════════════════════════════╯\n");
printf("\t\t\t\t ┌───────────────────────────────────────────-┐\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 1. 申请内存 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 2. 回收内存 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 3. 查看内存情况 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t │ 4. 退出 │\n");
printf("\t\t\t\t │ │\n");
printf("\t\t\t\t └────────────────────────────────────────────┘\n");
printf("\t\t\t\t\t\t 请您选择(1-4):\t");
}
int main(){
// node为整个空间
system("color 0f");
//system("mode con cols=120 lines=50");
struct nodespace *init = (struct nodespace*)malloc(sizeof(struct nodespace));
struct nodespace *node = NULL;
initNode(init); //初始化主链
node = init; //指向链表头
int option;
int teskid;
int size;
while(1){
menu(); //打印想要进行的操作
scanf("%d",&option);
if(option == 1){
printf("请输入作业号;");
scanf("%d",&teskid);
printf("此作业申请的空间大小(KB):");
scanf("%d",&size);
myMalloc1(teskid,size,node);
printf("\n");
printNode(node);
}else if(option == 2){
printf("请输入作业号:");
scanf("%d",&teskid);
myFree(teskid,node);
printf("\n");
printNode(node);
}else if(option == 3){
printNode(node);
}else if(option == 4){
destory(node);
initNode(init);
node = init;
break;
}else{
printf("===========================您的输入有误,请重新输入!============================\n");
continue;
}
}
return 0;
}