gpt4 book ai didi

c - 我想知道如果这个程序运行 24/7 操作系统会重载吗?

转载 作者:太空宇宙 更新时间:2023-11-04 08:01:08 25 4
gpt4 key购买 nike

没有语法错误,但我想知道如果这个程序 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 使用率不是问题。您没有超出任何内存限制,并且在使用后释放所有分配的内存,因此内存使用不是问题。

关于c - 我想知道如果这个程序运行 24/7 操作系统会重载吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46756699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com