简体   繁体   中英

What does it mean to receive a 0xcccccccccccccccc pointer value from std::partition?

I want to spatially partition some tree nodes, but I receive a 0xcccccccccccccccc pointer value from std::partition at a breakpoint while debugging. Does someone know what this means?

template <typename NodeData> struct PartitionPredicate {
    PartitionPredicate(float s, uint32_t a) : splitPos(s), splitAxis(a) {}
    float splitPos;
    uint32_t splitAxis;

    bool operator()(const NodeData *data) const {
        return data->p[splitAxis] <= splitPos;
    }
};

...
const NodeData **m = std::partition(&buildNodes[start], &buildNodes[end], PartitionPredicate<NodeData>(splitPos, splitAxis));
uint32_t mid = start + (m - &buildNodes[start]);
// buildNodes is of type const NodeData **
...

Values: start=0 , end=407838 (size of buildNodes vector)

m = 0xcccccccccccccccc
mid > 3000000000

I changed the type of start , end and mid to my uint32_t instead of int because I recieved a huge negative value for mid , but an acceptable value for m .

Edit : I placed the breakpoint too early. The returned pointer is not known yet and Visual Studio seems to precompute all nearby values based on their own default initialization.

buildNodes is located at 0x00000000050c0070 m is located at 0x0000000005161c58 so mid = 82616 -> ok

m is not initialized - it has no valid value yet. The actual value of 0xcccccccccccccccc is what system fills the memory with so that it is possible to detect uninitalized variables. This value is picked specifically so that it's "not a valid memory address" - that way, you can't accidentally or on purpose use the memory of an uninitialized variable without getting some sort of error or trap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM