91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 0M
    文件類型: .7z
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-09
  • 語言: 其他
  • 標(biāo)簽: 其他??

資源簡介

memory_management.7z

資源截圖

代碼片段和文件信息

#include?
#include?“process.h“
#include?“holes.h“
#define??MAX_PROCESS?100

int?holes_size;
hole_node?*holes;
process_array?*pa;
int?memorysize;
int?allocate_byte;
int?free_byte;

void?MemoryManager(int?bytes)
{?//?initialize?memory?with?these?many?bytes.
memorysize?=?bytes;
free_byte?=?bytes;
allocate_byte?=?0;
holes?=?init_hole(0bytes);
pa?=?init_process(MAX_PROCESS);
holes_size?=?1;
}

int?allocate(int?bytes?int?pid)
{?//?allocate?these?many?bytes?to?the?process?with?this?id
??//?assume?that?each?pid?is?unique?to?a?process
??//?return?1?if?successful
??//?return?-1?if?unsuccessful;?print?an?error?indicating
??//?whether?there?wasn’t?sufficient?memory?or?whether
??//?there?you?ran?into?external?fragmentation
if?(bytes?<=?0)
{
printf(“Process?size?should?be?positive.\n“);
return?-1;
}
if?(bytes?>?memorysize?-?allocate_byte)?{
printf(“Not?enough?memory?space?for?process?%d.\n“?pid);
return?-1;
}
/*search?first?hole?which?size?>=?bytes*/
hole_node?*s?=?search_hole(holes?bytes);
if?(s)
{//if?have?a?hole?to?add?process
process?p;
p.start?=?s->data.start;
p.size?=?bytes;
p.ID?=?pid;
if?(-1?==?add_process(pa?p))?{
printf(“Process?with?same?pid(%d)?already?exists.\n“?p.ID);
return?-1;
}
/*change?hole?after?add?process*/
allocate_byte?+=?bytes;
change_hole(s?bytes);
}
else
{
printf(“Memory?defragmentation.\n“);
/*creating?one?hole?at?the?high?region?of?memory*/
destory_hole(holes);
holes?=?init_hole(allocate_bytememorysize-allocate_byte);
holes_size?=?1;
/*compact?processes?to?the?start?of?main?memory*/
resort_process(pa);
allocate(bytes?pid);
}
}

int?deallocate(int?pid)
{?//deallocate?memory?allocated?to?this?process
??//?return?1?if?successful?-1?otherwise?with?an?error?message
process?p?=?del_process(pa?pid);
if?(p.ID?!=?-1)
{//?delete?successfully
hole?h;
h.start?=?p.start;
h.size?=?p.size;
allocate_byte?-=?p.size;
holes_size?+=?add_hole(holes?h);
return?1;
}
else
{
printf(“Process?with?pid(%d)?does?not?exist.\n“?pid);
return?-1;
}

}
void?printMemoryState()
{?//?print?out?current?state?of?memory
printf(“Memory?size?=?%d?bytes?allocated?bytes?=?%d?free?=?%d\n“?memorysize?allocate_byte?memorysize?-?allocate_byte);
printf(“There‘re?currently?%d?holes?and?%d?processes:\n“?holes_size?pa->size);
printf(“Hole?list:\n“);
int?j?=?1;
for?(hole_node?*i?=?holes->next;?i;?i?=?i->next?++j)
{
printf(“hole?%d:?start?location=%d?size=%d\n“?j?i->data.start?i->data.size);
}
printf(“\nProcess?list:\n“);
for?(int?i?=?0;?i?size;?++i)
{
printf(“process?%d:?id=%d?start?location=%d?size=%d\n“?i?+?1?pa->p[i].ID?pa->p[i].start?pa->p[i].size);
}
}

int?main()
{
int?msize;
FILE?*fin?=?fopen(“input.txt“?“r“);
if?(!fin)
{
printf(“file?not?found/n“);
return?-1;
}
fscanf(fin?“%d“?&msize);
MemoryManager(msi

評論

共有 條評論