Freeing (vfree-ing) pointer to volatile data

前端 未结 2 1440
-上瘾入骨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: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.

提交回复
热议问题