Raised This Month: $51 Target: $400
 12% 

help with optimization :(


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EclipseCP
BANNED
Join Date: Dec 2010
Old 02-09-2011 , 13:47   help with optimization :(
Reply With Quote #1

hello all . use translator

There is some way of optimizing this code?

PHP Code:
new g_counter_nemesis[33]
new 
g_counter_multimod[33]
new 
g_counter_swarmmod[33]
new 
g_counter_survivor[33]
new 
g_counter_plaguemod[33]
new 
g_counter_synapsismod[33]
new 
g_counter_armagedonmod[33
This serves me to add the variable when it orders a way in the Zombie Plague

PHP Code:
len += formatex(menu[len], charsmax(menu) - len"\r1.\w %L (%d)^n"id"MENU_ADMIN1"g_counter_nemesis[id])

len += formatex(menu[len], charsmax(menu) - len"\r2.\w %L (%d)^n"id"MENU_ADMIN1"g_counter_survivor[id])

// etc.

g_counter_nemesis[id]++
g_counter_survivor[id]++

//[...] 
grettings
EclipseCP is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-09-2011 , 14:12   Re: help with optimization
Reply With Quote #2

g_asd[8]
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
EclipseCP
BANNED
Join Date: Dec 2010
Old 02-09-2011 , 15:12   Re: help with optimization
Reply With Quote #3

Okay, but when adding the variable and display the number on the menu?
EclipseCP is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-09-2011 , 15:22   Re: help with optimization
Reply With Quote #4

Quote:
Originally Posted by lucas_7_94 View Post
g_asd[33][8]
Fixed, but it wouldn't be an optimization.


@EclipseCP
Can all 8 mods be used at the same time ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-09-2011 , 15:27   Re: help with optimization :(
Reply With Quote #5

oh , i leave that , thanks.
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
EclipseCP
BANNED
Join Date: Dec 2010
Old 02-09-2011 , 15:40   Re: help with optimization :(
Reply With Quote #6

Hello, may I express it

I have an admin menu where I can send Anyway, I wanted to do anyway likely to command a number of times each (I do not make 8 variables as consuming and would be more work)

Sorry for my bad english ;)
EclipseCP is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 02-10-2011 , 23:15   Re: help with optimization :(
Reply With Quote #7

You can optimize by 8*4 bytes here on data:
PHP Code:
new g_counter_nemesis[33];
len += formatex(menu[len], charsmax(menu) - len"\r1.\w %L (%d)^n"id"MENU_ADMIN1"g_counter_nemesis[id]); 
=>
PHP Code:
new g_counter_nemesis[32];
len += formatex(menu[len], charsmax(menu) - len"\r1.\w %L (%d)^n"id"MENU_ADMIN1"g_counter_nemesis[id-1]); 
You can edit all your arrays from 33 to 32, because there is no player id #0, so for example
g_counter_nemesis[0] would never be used.

A 32 bit integer can hold a value from -2147483648 to +2147483647. And I am sure, your g_counter_nemesis[id] will never reach that much value.
If you limit g_counter_nemesis[id] to -32768 to 32767, then your container( g_counter_nemesis ) can hold 2 times it's size.
So this would be enough for all arrays
new g_counter_nemesis[16];

For 32 bit servers:
PHP Code:
stock get_packed_data(const container[], id)
{
    
id--;
    new 
data container[id >> 1];
    if(
id 1)
    {
        
data >>= 16;
    }
    else
    {
        
data &= 0xffff;
    }
    return 
data;
}

stock set_packed_data(container[], idnumber)
{
    
id--;
    new 
data container[id >> 1];
    if(
id 1)
    {
        
data &= 0xffff;
        
number <<= 16;
        
data |= number;
    }
    else
    {
        
data &= 0xffff0000;
        
data |= number;
    }
}

new 
g_counter_nemesis[16];

len += formatex(menu[len], charsmax(menu) - len"\r1.\w %L (%d)^n"id"MENU_ADMIN1"get_packed_data(g_counter_nemesisid));

set_packed_data(g_counter_nemesisid, ++get_packed_data(g_counter_nemesisid)); 
I need to mention again, this may not be faster, but it only needs half the memory you used.

If you have a 64 bit server, and the 0..32767 limit is still enough, then you could use even the half of my code ( g_counter_nemesis[8] ), but I am too lazy to code it now.
( Ask me if you need it )

So please tell me, if your counters would have a limit( maybe (-128..)0..127 is enough ? or (-8..)0..7 )
Of course, if you don't want to use negative numbers, then the limit is 0..65535( 0..255, 0..16 ).

Last edited by Lulu the hero; 02-10-2011 at 23:56.
Lulu the hero is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-11-2011 , 04:53   Re: help with optimization :(
Reply With Quote #8

I made a plugin , but i get errors in console server.

Code:
#include <amxmodx> #include <amxmisc> #include < hamsandwich > #define PLUGIN "Hi bailopán." #define VERSION "1.0" #define AUTHOR "Luqqas" const MAX_OPTIONS = 3 enum _:LOL {     Option[32],     Max_Cost, } new const Faint[MAX_OPTIONS][LOL] = {     { "Opcion 1", 5 },     { "Opcion 2", 4 },     { "Opcion 3", 3 } } new menu new MAX[33][MAX_OPTIONS] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("nightvision", "asd")     register_clcmd("say /resetcount", "clcmd_reset") } public asd(id) {     menu = menu_create("FUN LUQQAS LOL", "zomg")             new Format[245], Posicion[MAX_OPTIONS]         for(new i = 0 ; i < MAX_OPTIONS; i++)     {         if(Faint[i][Max_Cost] == MAX[id][i])             formatex(Format, charsmax(Format), "%s [NO DISPONIBLE]", Faint[i][Option])         else             formatex(Format, charsmax(Format), "%s [%d/%d]", Faint[i][Option], MAX[id][i], Faint[i][Max_Cost])                 num_to_str(i, Posicion, sizeof(Posicion))         menu_additem(menu, Format, Posicion)     }         menu_setprop(menu, MPROP_EXITNAME, "\ySalir")     menu_display(id, menu)     return PLUGIN_HANDLED } public zomg(id, menuid, item) {     if(item == MENU_EXIT)     {         menu_destroy(menuid)         return PLUGIN_HANDLED;     }             new buffer[MAX_OPTIONS], dummy
    menu_item_getinfo(menuid, item, dummy, buffer, charsmax(buffer), _, _, dummy)
    new lol     lol = str_to_num(buffer)         if(Faint[lol][Max_Cost] == MAX[id][lol])     {         client_print(id, print_center, "[ Limite Alcanzado. ]")         menu_display(id, menu, 0)         return PLUGIN_HANDLED     }     MAX[id][lol]++         client_print(id, print_center, "~ Opcion %d | Valor Max : %d", lol, MAX[id][lol])     menu_display(id, menu, 0)     return PLUGIN_HANDLED } public clcmd_reset(id) {     for( new i = 0 ; i < MAX_OPTIONS ; i++)         MAX[id][i] = 0;         client_print(id, print_center, "[RESETEADO]") }

Code:
L 02/10/2011 - 12:06:53: Invalid menu id 1(2)
L 02/10/2011 - 12:06:53: [AMXX] Displaying debug trace (plugin "testLOL.amxx")
L 02/10/2011 - 12:06:53: [AMXX] Run time error 10: native error (native "menu_item_getinfo")
L 02/10/2011 - 12:06:53: [AMXX]    [0] testLOL.sma::zomg (line 60)
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 02-11-2011 at 05:17.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-11-2011 , 04:58   Re: help with optimization :(
Reply With Quote #9

Changing 33 to 32 is not an optimization. It's more convenient to use 33 and less ugly so you don't have to do the "-1" operation each time, which can be lead to errors. It doesn't matter to add an extra cell and can be useful sometimes to have the 0 as index.
Also, I don't understand your packed data thing. You create more code just for reducing a bit the memory used -> not worth for this case. Generally you would optimize the code for speed, not for memory.
But here, that's not about memory or speed, but more about code design.
__________________

Last edited by Arkshine; 02-11-2011 at 05:01.
Arkshine is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 02-11-2011 , 10:36   Re: help with optimization :(
Reply With Quote #10

Quote:
Originally Posted by Lulu the hero View Post
I need to mention again, this may not be faster, but it only needs half the memory you used.
EclipseCP didn't mention the optimization way. There is only 2 optimizating edges: memory or speed. I provided the memory version.

Last edited by Lulu the hero; 02-11-2011 at 10:38.
Lulu the hero is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode