is Vector must be ptr_remove?

Posted By: frankjiang

is Vector must be ptr_remove? - 01/29/18 06:22

Code:
VECTOR* tarPos = vector(x,y,0);
ptr_remove(tarPos);//is tarPos must be ptr_remove?any one know that?

Posted By: MasterQ32

Re: is Vector must be ptr_remove? - 01/29/18 07:12

No, vector() returns a temporary vector, which means, it cycles through 64 pre-created vectors and returns a pointer to one of them (round robin style)

so if you remove a vector, you will most likely get a crash, but even if not, you won't get predictable behaviour and bugs one cannot comprehend

the function most likely looks something like this:

Code:
VECTOR storage[64];
int index = 0;

VECTOR * vector(var x, var y, var z)
{
    VECTOR * vec = &storage[index];
    index += 1;
    if(index >= 64)
        index = 0;
    vec->x = x;
    vec->y = y;
    vec->z = z;
    return vec;
}

Posted By: frankjiang

Re: is Vector must be ptr_remove? - 01/29/18 07:24

Originally Posted By: MasterQ32
No, vector() returns a temporary vector, which means, it cycles through 64 pre-created vectors and returns a pointer to one of them (round robin style)

so if you remove a vector, you will most likely get a crash, but even if not, you won't get predictable behaviour and bugs one cannot comprehend

the function most likely looks something like this:

Code:
VECTOR storage[64];
int index = 0;

VECTOR * vector(var x, var y, var z)
{
    VECTOR * vec = &storage[index];
    index += 1;
    if(index >= 64)
        index = 0;
    vec->x = x;
    vec->y = y;
    vec->z = z;
    return vec;
}



so your means is not need to ptr_remove?
Posted By: MasterQ32

Re: is Vector must be ptr_remove? - 01/30/18 07:06

yes, don't ptr_remove. if you do, your program will have horribly bad errors, most probably in other parts of your code
Posted By: frankjiang

Re: is Vector must be ptr_remove? - 01/30/18 13:10

Ok ,i see,thank for your answer.
© 2024 lite-C Forums