什么是“保鲜存储”在夹板?

发布于 2024-12-29 17:06:35 字数 1764 浏览 1 评论 0原文

我在 Splint 文档中搜索了“新鲜存储”,并发现了它的提及,但没有正式的定义。其他修饰符,例如 null 或 only,我理解并正在使用。我只是不确定什么是新鲜存储。

情况是这样的:

void output_system_information(unsigned int frequency, unsigned int duration) { 

   unsigned int intervals = duration/frequency;                                  

   /* here I allocate some storage */                                                                              
   System * my_system = malloc(sizeof(System));                                  

   SystemInfo* current, * total;                                                 

   if (my_system == NULL) {                                                      
     fprintf(stderr, "%s\n", "Aborting: failed malloc in output_system_informatioin");
     exit(EXIT_FAILURE);                                                         
   }                                                                             

   /* and here I initialize is in that function */                                              
   init_system(my_system);      
   total = tally_system_info(frequency, duration, my_system);                    
   current = my_system->get_system_info();                                       

   /* Here I've removed a ton of print-line statements so that you don't have to see them */

   /* then the members and the struct get freed in this here dtor */
   delete_system(my_system);                                                     
   free(current);                                                                
   free(total);                                                                  

   return;                                                                       
}            

这是一个家庭作业,但是这个问题与家庭作业没有直接关系。这是一个夹板问题。

I have searched the Splint documentation for "fresh storage", and have found mention of it, but no formal definition. The other modifiers, like null or only, I understand and am putting to use. I'm just not sure what fresh storage is.

The situation is this:

void output_system_information(unsigned int frequency, unsigned int duration) { 

   unsigned int intervals = duration/frequency;                                  

   /* here I allocate some storage */                                                                              
   System * my_system = malloc(sizeof(System));                                  

   SystemInfo* current, * total;                                                 

   if (my_system == NULL) {                                                      
     fprintf(stderr, "%s\n", "Aborting: failed malloc in output_system_informatioin");
     exit(EXIT_FAILURE);                                                         
   }                                                                             

   /* and here I initialize is in that function */                                              
   init_system(my_system);      
   total = tally_system_info(frequency, duration, my_system);                    
   current = my_system->get_system_info();                                       

   /* Here I've removed a ton of print-line statements so that you don't have to see them */

   /* then the members and the struct get freed in this here dtor */
   delete_system(my_system);                                                     
   free(current);                                                                
   free(total);                                                                  

   return;                                                                       
}            

This is a homework assignment, but this question doesn't have to do directly with the homework. This is a splint question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2025-01-05 17:06:35

术语新鲜存储指的是刚刚为您的程序分配的内存缓冲区。

警告“新鲜存储未释放”只是“仅存储未释放”的特殊情况,当缓冲区由无法释放它的同一函数分配时。

The term fresh storage refers to a memory buffer which has been just allocated for your program.

The warning "Fresh storage not released" is just a special case of "Only storage not released", when the buffer is allocated by the same function which fails to release it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文