本文介绍了释放(vfree-ING)指针性数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

挥发性似乎是每个人无休止的问题。我想我知道它的一切,但后来我遇到过这样的:

volatile seems to be a never ending question of every one. I thought I knew everything about it, but then I encountered this:

所以,我有一块线程之间共享内存和我定义它是这样的:

So, I have a piece of memory shared between threads and I defined it like this:

volatile type *name;

如果它让你感觉更好,你可以想像键入只是一个 INT

If it makes you feel better, you can imagine type is just an int.

这意味着我有一个指针(即不挥发),一些数据是易失。因此,例如,当涉及到优化,编译器可以缓存名称的价值,但不名称[0] 。我说得对不对?

This means I have a pointer (that is not volatile) to some data that are volatile. So, for example when it comes to optimizing, the compiler can cache the value of name but not name[0]. Am I right?

所以,现在我 vfree ING这个指针(这是一个Linux内核模块),它告诉我, vfree 预计常量无效* 当我向它传递挥发型*

So, now I am vfreeing this pointer (it's in a Linux kernel module) and it tells me that vfree expects const void * while I am passing it volatile type *.

我明白怎么可以是危险传递一个挥发型* 键入* ,因为该功能,名称的值[I] 可缓存(作为优化的结果),这是不可取的。

I understand how it can be dangerous to pass a volatile type * as a type * because in that function, the values of name[i] could be cached (as a result of optimization) which is not desirable.

我不明白为什么,虽然, vfree 希望我的指针不一定发送到非易失性数据。是否有我丢失的东西吗?或者是谁写的没有考虑这种情况,它只是球员 vfree

I don't understand why though, vfree expects me to send it a pointer necessarily to non-volatile data. Is there something I am missing there? Or is it just the guys who wrote vfree not thinking about this situation?

我想我只是铸造我指针无效* 将不会造成任何伤害,是这样吗?

I assume me simply casting my pointer to void * would not cause any harm, is that right?

推荐答案

我的结论是,只是投放指针无效* 不会造成问题,事实上, 免费 vfree 不直接接受指针挥发性数据只是一些被忽视了。

My conclusion was that just casting the pointer to void * would not cause a problem and the fact that free and vfree don't directly accept pointers to volatile data is just something that was overlooked.

这篇关于释放(vfree-ING)指针性数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:56