[英]how does a program runs in memory and the way memory is handled by Operating system
[英]I want to know if this program runs 24/7 will the operating system get overloaded?
沒有語法錯誤,但我想知道該程序是否24/7運行,操作系統會過載嗎? 以及如何測試內存? 我的意思是有多少個未使用的變量? 我在Visual Studio中編寫了這段代碼,可能會有一些變化。
struct video{
char category[10];
long long int rating;
};
int main(void){
srand((unsigned int)time(0));
while (1) {
struct video* gaming = (struct video*) malloc(sizeof(*gaming));
struct video* music = (struct video*) malloc(sizeof(*music));
struct video* vlog = (struct video*) malloc(sizeof(*vlog));
strcpy_s(gaming->category, 7, "Gaming");
strcpy_s(music->category, 6, "Music");
strcpy_s(vlog->category, 5, "Vlog");
gaming->rating = rand() % 10000000 + 1;
music->rating = rand() % 10000000 + 1;
vlog->rating = rand() % 10000000 + 1;
printf("Category: %s Rating: %lld",gaming->category,gaming->rating);
printf("Category: %s Rating: %lld",music->category,music->rating);
printf("Category: %s Rating: %lld",vlog->category,vlog->rating);
Sleep(3000);
system("cls");
free(gaming);
free(music);
free(vlog);
}
}
不,操作系統不會“過載”。
循環的每個迭代都有3秒的睡眠時間,並且每次迭代都進行得很少,因此CPU使用率不是問題。 您不會超出任何內存范圍,並且可以釋放使用后分配的所有內存,因此內存使用率不是問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.