Native support for pointers as integers

Moderator: GZDoom Developers

User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Native support for pointers as integers

Post by Apeirogon »

For testing reasons I needed to get the address of an objects, to differentiate between them from each other.
And the only way its possible to get it is

Code: Select all

int self_pointer = string.format("%p", self).toint(10);
which is works, yes, but it looks like a hack.

Add native support for pointers as integers please.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49211
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Native support for pointers as integers

Post by Graf Zahl »

No, no, no. If you want to differentiate between objects, compare the pointers. It won't even work because pointers are 64 bit values and integers are 32 bit values.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Native support for pointers as integers

Post by Apeirogon »

Problem in this case is, its impossible to transfer actors pointer, as a zscript thing, through network event to the ui side.
I use on screen custom made table that, internally, uses actor pointers to differentiate them. Because dumping all info into the console becomes old too fast with more than one target.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49211
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Native support for pointers as integers

Post by Graf Zahl »

In that case a string with "%p" output is your only option.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Native support for pointers as integers

Post by Apeirogon »

I made this instead

Code: Select all

class six_four_pointer
{
    private uint mantissa, radix;
    void construct(string s)
    {
        int substring_len = s.Length()/2;
        mantissa = s.Mid(0, substring_len ).toint(16);
        radix = s.Mid(substring_len, substring_len ).toint(16);
    }

    clearscope uint get_pointer(bool main = true) const
    {
        if(main)
            return mantissa;
        else
            return radix;
    }
}
It still cheaper than comparing >9000 strings to find corresponding (to the actor) entries in the table.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49211
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Native support for pointers as integers

Post by Graf Zahl »

No, that's actually not cheaper at all. You are totally overestimating the cost of a string comparison. The internal overhead of calling get_pointer twice is magnitudes higher than doing a string comparison due to the call oveehead of scripted code.,
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Native support for pointers as integers

Post by Apeirogon »

'Tested' both integer and string versions and they work approximately with the same speed.
'tested', because if I made more than around 30 "send network event" calls per single tick, Gzdoom crashes WITHOUT very fatal error window.
User avatar
Redneckerz
Spotlight Team
Posts: 1112
Joined: Mon Nov 25, 2019 8:54 am
Graphics Processor: Intel (Modern GZDoom)

Re: Native support for pointers as integers

Post by Redneckerz »

Apeirogon wrote:'Tested' both integer and string versions and they work approximately with the same speed.
'tested', because if I made more than around 30 "send network event" calls per single tick, Gzdoom crashes WITHOUT very fatal error window.
If the answer is '''No, and here is why'' i fail to understand why you then go on the defence for your own implementation which does the same but is likely more expensive in the long run.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Native support for pointers as integers

Post by Apeirogon »

????
I done X in Y way
Do X in Z way instead, its faster this way
I compared Y and Z ways, they works approximately with same speed, but I had small testing sample set, due to a bug
User avatar
Rachael
Posts: 13885
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Native support for pointers as integers

Post by Rachael »

I think this topic has reached an appreciable level of tug roping and hair pulling now at this point.

Return to “Closed Feature Suggestions [GZDoom]”