Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабораторная работа №41

.cpp
Скачиваний:
13
Добавлен:
01.05.2014
Размер:
2.72 Кб
Скачать
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include <conio.h>
int main(int argc, char* argv[])
{	
	printf("---------------- function GlobalMemoryStatus ------------------\n\n");
	MEMORYSTATUS memstat;
	GlobalMemoryStatus(&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");
	DWORD dwMemSize;
	MEMORY_BASIC_INFORMATION meminfo;
	printf("---------------- function VirtualAlloc ------------------\n\n");
	printf("   Enter the size of memory to commit (bytes): ");
	cin >> dwMemSize;
	LPVOID lpAllocAddr = VirtualAlloc(NULL, dwMemSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
	getch();
	if (lpAllocAddr==NULL) printf("Error: %u\n",GetLastError());
	else 
	{
		printf("Memory reserved. Addres:  %p\n",lpAllocAddr);
		printf("---------------- function VirtualQuery ------------------\n\n");
		DWORD dwBytes = VirtualQuery(lpAllocAddr,&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);
		getch();
		printf("\n---------------- function VirtualFree  ------------------\n\n");
		if(!VirtualFree(lpAllocAddr, 0, MEM_RELEASE))	printf("Error: %u\n",GetLastError());
		else printf("Memory freed.\n");
	}
    getch();
	return 0;
}
Соседние файлы в предмете Операционные системы