简体   繁体   中英

Unused bits in pointer (iPhone)

Box2d objects have a void* m_userData field where the user can store data. Typically you store a pointer to another object, for instance a pointer to a sprite that shall be updated with location information every system tick.

I want to store a pointer to another object, but I would be glad if I also could store one extra bit of information. Can I do that in the most significant bit of the pointer? Could the most significant bit of an object pointer be set? I mean the internal memory is only 512 MB (I guess).

Maybe the app be rejected because of this? It's not completely future proof, and it's a bit of a hack...

The pointer to 'another object' can be whatever you like, so the typical way to do this would be to make a struct/class to hold whatever you want to store in the user data, eg:

struct myUserData {

    Object* anObject;
    AnotherObject* anotherObject;
    bool oneExtraBit;//okay, 8 extra bits :)

}

Then you would set one of these as the user data...

myUserData* mud = new myUserData;
mud->anObject = ...;
mud->oneExtraBit = ...;
myBody->SetUserData( mud );

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