澳门葡亰娱乐场手机版-澳门新葡亰手机娱乐网址

c回收内存(回收内存)

文章发布时间:2019-09-30 22:09:37
回收

回收内存

  做数据恢复可以用。
  比如有个硬盘电路板烧掉了,可以用同型号的替换后恢复数据。
  当然,如果硬盘坏的不厉害,也能修复硬盘。

关于内存回收正确的是

B是对的
A. 程序员不需要创建线程来释放内存。
C. 也不允许程序员直接释放内存。
D. 不一定在什么时刻执行垃圾回收。

内存的分配与回收

#include “iostream.h”
#include “iomanip.h”

#define nofreearea 2
#define noadequacyarea 3
#define allocated 4

#define noprocess 2
#define nosuchprocess 3
#define reclaimed 4

typedef struct TUN
{
int address;
int size;
char name;
struct TUN *next;
} usedarea , *usedtable;

typedef struct TFN
{
int address;
int size;
struct TFN *next;
} freearea, *freetable;

usedtable usedTable = NULL;
freetable freeTable = NULL;

int alloc( char processname , int processsize )
{

if( freeTable == NULL )
return 1;
freetable p = freeTable;
freetable q = p;

while( p != NULL && p->size < processsize )
{
q = p;
p = p->next;
}

if( p == NULL )
return 3;

usedtable x = new usedarea;
x->address = p->address;
x->size = processsize;
x->name = processname;
x->next = NULL;

if( p->size > processsize )
{
p->size -= processsize;
p->address += processsize;
}

else
{
if( p == freeTable )
freeTable = NULL;
else
q->next = p->next;
delete p;
}

usedtable r = usedTable;
usedtable t = r;

while( r != NULL && r->address address )
{
t = r;
r = r->next;
}

if( usedTable == NULL )
usedTable = x;
else
{
x->next = r;
t->next = x;
}

return 4;
}

int Reclaim( char processname )
{
if( usedTable == NULL )
return 1;
usedtable p = usedTable;
usedtable q = p;
while( p != NULL && p->name != processname )
{
q = p;
p = p->next;
}

if( p == NULL )
return 3;

freetable r = freeTable;
freetable t = r;
freetable x;
while( r != NULL && r->address address )
{
t = r;
r = r->next;
}

x = new freearea;
x->address = p->address;
x->size = p->size;
x->next = NULL;

if( r == freeTable )
{
x->next = r;
freeTable = x;
t = freeTable;
}
else
{
x->next = r;
t->next = x;
}

while( t->next != NULL && t->address + t->size == t->next->address )
{
t->size += t->next->size;
r = t->next;
t->next = t->next->next;
delete r;
}

if( p == usedTable )
{
usedTable = usedTable->next;
}
else
q->next = p->next;
delete p;

return 4;
}

int Init()
{
freeTable = new freearea;
freeTable->address = 0;
freeTable->size = 128;
freeTable->next = NULL;
return 1;
}

void processrequest()
{
char processname;
int processsize;
cout<<"……………….."<<endl;
cout<<"作业名: ";
cin >> processname;
cout<<"作业长度: ";
cin >> processsize;
if(processsize<=128)
{int i;
if( alloc( processname , processsize) == 4 )
{
i=i+processsize;
if(i>128)
{cout<<"该作业超出空间"<<endl;
}
if(i<=128)
cout<<"该作业已成功获得所需空间"<<endl;
i=i+processsize;
cout<<"…………………………………."<<endl;

}
else
cout<<"该作业超出空间,没有获得所需空间"<<endl;
cout<<"…………………………………."<<endl;
return;
}
if(processsize>128)
{cout<<"该作业超出空间"<<endl;
cout<<"…………………………………."<<endl;
}

}

void processreclaim()
{
int processname;
cout<<"……………….."<<endl;
cout<<"作业名: ";
cin >>processname;
int result = Reclaim( processname );
if( result == 4 )
cout<<"该作业已成功回收"<<endl;
else if( result == 2 || result == 1 )
cout<<"系统没有作业或该作业不存在"<<endl;
cout<<"……………….."<<endl;

}

void freeTablePrint()
{
cout<<endl<<endl<<endl<<"***********************************"<<endl;
cout<<setw(10)<<"address"<<setw(10)<<"length"<<setw(10)<<"state"<<endl<<endl;
freetable p = freeTable;
usedtable q = usedTable;
int x , y;
while( p || q )
{
if( p )
x = p->address;
else
x = 0x7fffffff;
if( q )
y = q->address;
else
y = 0x7fffffff;

if( x < y )
{
cout<<setw(10)<address<<setw(10)<size<<setw(10)<<"空闲"<<endl;
p = p->next;
}
if( x > y )
{
cout<<setw(10)<address<<setw(10)<size<<setw(10)<<"已分配"<<setw(10)<<"ID="<name<<endl;
q = q->next;
}
}
cout<<endl<<endl<<endl<<"************************************"<<endl<<endl<<endl;

}

void main()
{
Init();
int choose;
bool exitFlag = false;
while( !exitFlag )
{

cout<<"************************0 – 退出 ************************"<<endl;
cout<<"************************1 – 分配主存 ************************"<<endl;
cout<<"************************2 – 回收主存 ************************"<<endl;
cout<<"************************3 – 显示主存 ************************"<<endl<<endl<<endl;
cout<<"************************选择所要执行的操作:";
cin>>choose;
switch( choose )
{
case 0:
exitFlag = true;
break;
case 1:
processrequest();
break;
case 2:
processreclaim();
break;
case 3:
freeTablePrint();
break;
}
}
}

高价回收内存

你编写程序,程序的一些变量会申请内存去存储。比如你在一个函数里面定义了一个变量(那么我们通常说这个变量是局部变量,只能在该函数内部使用),程序会将该变量存储在该函数的堆栈中,那么在函数执行完之后,堆栈的内容就要清理,这就可以理解为回收内存。如今的java和.net的GC回收机制都很好。不需要程序员做太多的事情。(我们将这些可以自动回收的资源叫做托管资源),其他一些非托管资源,比如数据库链接,文件等等,是需要我们自己去关闭的。

哪里回收内存条

淘宝上二手卖掉。问你几个问题:
1.你的内存是台式机的还是笔记本的?
2.你的内存条是DDR2 还是 DDR3 ? 频率是多少的?

继续阅读
XML 地图 | Sitemap 地图