
Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа №42
.cpp#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include <conio.h>
int main(int argc, char* argv[])
{ DWORD address=0;
LPVOID lpAllocAddr,l,add;
MEMORYSTATUS memstat;
GlobalMemoryStatus(&memstat);
DWORD dwMemSize;
MEMORY_BASIC_INFORMATION meminfo;
DWORD dwBytes;
int n=1;
while(n!=0)
{
_SYSTEM_INFO S;
GetSystemInfo(&S);
printf("Page Size %d\n",S.dwPageSize);
printf("Minimum Application Address: %\n",S.lpMinimumApplicationAddress);
printf("Maximum Application Address: %p\n",S.lpMaximumApplicationAddress);
printf("Allocation Granularity %d\n",S.dwAllocationGranularity);
printf("\n\n\n\n1 - Memory status\n");
printf("2 - Virtual allocation\n");
printf("3 - Virtual query\n");
printf("4 - Virtual free\n");
printf("0 - Exit\n");
scanf("%d",&n);
switch(n)
{
case 0:
exit(1);
case 1:
memstat.dwLength=sizeof(memstat);
printf("Percent of memory in use: %u\n",memstat.dwMemoryLoad);
printf("_________________________________________________________________\n");
printf("Bytes of physical memory: %u\n",memstat.dwTotalPhys);
printf("_________________________________________________________________\n");
printf("Free physical memory bytes: %u\n",memstat.dwAvailPhys);
printf("_________________________________________________________________\n");
printf("Bytes of paging file: %u\n",memstat.dwTotalPageFile);
printf("_________________________________________________________________\n");
printf("Free bytes of paging file: %u\n",memstat.dwAvailPageFile);
printf("_________________________________________________________________\n");
printf("User bytes of address space: %u\n",memstat.dwTotalVirtual);
printf("_________________________________________________________________\n");
printf("Free user bytes: %u\n",memstat.dwAvailVirtual);
printf("_________________________________________________________________\n");
break;
case 2:
printf("---------------- function VirtualAlloc ------------------\n\n");
printf(" Enter the size of memory to commit (bytes): ");
cin >> dwMemSize;
printf("enter address\n");
scanf("%p",&address);
printf("\n");
l=(void*)address;
printf("\n\n:: %p",l,"\n\n");
lpAllocAddr = VirtualAlloc(l, dwMemSize, MEM_COMMIT, PAGE_READWRITE);
if (lpAllocAddr==NULL) printf("Error: %u\n",GetLastError());
else
printf("Memory reserved. Addres: %p\n",lpAllocAddr);
break;
case 3:
scanf("%p",&add);
dwBytes = VirtualQuery((void*)add,&meminfo,sizeof(meminfo));
printf("Range of pages in the virtual address space of the calling process: %u\n\n",dwBytes);
printf("base address of region: %p\n",meminfo.BaseAddress);
printf("allocation base address: %p\n",meminfo.AllocationBase);
//printf("initial access protection: %p\n",meminfo.AllocationProtect);
printf("size, in bytes, of region: %u\n",meminfo.RegionSize);
//printf("committed, reserved, free: %u\n",meminfo.State);
//printf("current access protection : %u\n",meminfo.Protect);
//printf("type of pages : %u\n",meminfo.Type);
if(meminfo.State & MEM_COMMIT)
printf("Committed pages for which physical storage has been allocated\n");
if(meminfo.State & MEM_FREE)
printf("Free pages not accessible to the calling process and available to be allocated\n");
if(meminfo.State & MEM_RESERVE)
printf("Virtual address space is reserved without allocating any physical storage\n");
break;
case 4:
printf("\n---------------- function VirtualFree ------------------\n\n");
if(!VirtualFree(lpAllocAddr, dwMemSize, MEM_DECOMMIT)) printf("Error: %u\n",GetLastError());
else printf("Memory freed.\n");
break;
default:
printf("Invalid number\n");
break;
}
} getch();
return 0;
}
Соседние файлы в предмете Операционные системы