Is the pointer guaranteed to be > a certain value?

前端 未结 5 1463
猫巷女王i
猫巷女王i 2021-01-18 17:37

In C++ when i do new (or even malloc) is there any guarantee that the return address will be greater than a certain value? Because... in this project i find it

5条回答
  •  甜味超标
    2021-01-18 18:10

    There's no such guarantee. You can try using placement new if you need very specific memory locations but it has certain problems that you'll have to work hard to avoid. Why don't you try using a map with an integer key that has the pointer as its value instead? That way you wouldn't have to rely on specific memory addresses and ranges.

提交回复
热议问题