WEAPON_X | Date: Tuesday, 26.06.2012, 03:19 | Message # 1 |
Group: User
Messages: 12
Status: Offline
| In jassapi we have this helpful and flexible macros
#define ENT_FROM_NUM(index) ((gentity_t*)((byte*)g_gents + g_gentsize * (index))) #define NUM_FROM_ENT(ent) ((int)((byte*)(ent) - (byte*)g_gents) / g_gentsize)
In my case, I am specifically targeting a mod, for which I have the correct entity structures in my header and therefore don't really benefit from the flexible macros.
Is there some difference between using the macro and using &g_gents[num] or ent-g_gents. Am I right to think that the latter simply bypass multiplication and division and is therefore (very slightly) preferable in my case?
|
|
| |
BufferOverflow | Date: Tuesday, 26.06.2012, 13:36 | Message # 2 |
Group: Developer
Messages: 47
Status: Offline
| ent-g_gents isn't exactly ent-g_gents, compiler interprets it as ((int)ent-(int)g_gents)/sizeof(gentity_t). So, you won't get any optimization, the only difference will be that sizeof(gentity_t) is constant. Yet, ENT_FROM_NUM is slower than &g_gents[num] coz this will be assembled that way: mov edi, g_gents mov ecx, num lea eax, [edi+ecx*sizeof(gentity_t)] Multiplication by g_gentsize not works the same way coz it isn't const
|
|
| |