Freeing (vfree-ing) pointer to volatile data

前端 未结 2 1438
-上瘾入骨i
-上瘾入骨i 2021-01-25 00:44

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 s

相关标签:
2条回答
  • 2021-01-25 01:30

    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.

    0 讨论(0)
  • 2021-01-25 01:43

    The vfree function (and every sane deallocation function in general) does not care about your actual data (be it volatile or not). It just expects a (valid) pointer (think: passing the pointer as a long value in a CPU register).

    Based on that value, the function will:

    1. call the SLAB/SLUB to free the memory
    2. remove the memory mapping

    So yes, casting to a void * will not cause any harm at runtime.

    0 讨论(0)
提交回复
热议问题