AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CPU Usage vs Memory Usage (https://forums.alliedmods.net/showthread.php?t=93197)

Exolent[jNr] 05-25-2009 14:59

CPU Usage vs Memory Usage
 
Which would be a better trade-off?

Option #1:
Code:
#define MAX_ENTITY_INDEX 1600 new bool:g_special_entity[MAX_ENTITY_INDEX]; public plugin_init() {     register_forward(FM_AddToFullPack, "FwdAddToFullPack", 1);         new ent = -1;     while( (ent = find_ent_by_class(ent, "_classname_"))     && ent < MAX_ENTITY_INDEX )     {         g_special_entity[ent] = true;     } } public FwdAddToFullPack(es, e, ent, host, hostflags, player, pset) {     if( ent < MAX_ENTITY_INDEX     && g_special_entity[ent] )     {         // code     } }

Option #2:
Code:
#define SPECIAL_ENTITY 123456 public plugin_init() {     register_forward(FM_AddToFullPack, "FwdAddToFullPack", 1);         new ent = -1;     while( (ent = find_ent_by_class(ent, "_classname_")) )     {         set_pev(ent, pev_iuser1, SPECIAL_ENTITY);     } } public FwdAddToFullPack(es, e, ent, host, hostflags, player, pset) {     if( pev(ent, pev_iuser1) == SPECIAL_ENTITY )     {         // code     } }

Option #3:
(This wasn't originally included, but I'm curious)
Code:
#define MAX_ENTITY_INDEX 1600 new g_special_entity[(MAX_ENTITY_INDEX >> 5) + 1]; public plugin_init() {     register_forward(FM_AddToFullPack, "FwdAddToFullPack", 1);         new ent = -1;     while( (ent = find_ent_by_class(ent, "_classname_"))     && ent < MAX_ENTITY_INDEX )     {         g_special_entity[ent >> 5] |= (1 << (ent & 31));     } } public FwdAddToFullPack(es, e, ent, host, hostflags, player, pset) {     if( ent < MAX_ENTITY_INDEX     && (g_special_entity[ent >> 5] & (1 << (ent & 31))) )     {         // code     } }

Brad 05-25-2009 15:42

Re: CPU Usage vs Memory Usage
 
I didn't look at your code, I just read the topic title. My answer is this: You're not going to get busted by a GSP for a little bit higher memory usage as much as you'd get busted for raising the CPU usage.

ConnorMcLeod 05-25-2009 15:54

Re: CPU Usage vs Memory Usage
 
<3 option 3, + doesn't use lot of memory :)
For such a forward, you have better to limit native calls as much as you can.

W/o option 3, 1600 is not so big, as you may use this size for a motd for example.
I think [1600] vs [1600>>5] is negligeable (cpu usage) if you compare [1600] vs entity_get_XXX.

Exolent[jNr] 05-25-2009 16:03

Re: CPU Usage vs Memory Usage
 
Quote:

Originally Posted by Brad (Post 834616)
You're not going to get busted by a GSP for a little bit higher memory usage as much as you'd get busted for raising the CPU usage.

Very true. I didn't think about that :)

Quote:

Originally Posted by ConnorMcLeod (Post 834629)
<3 option 3, + doesn't use lot of memory :)
For such a forward, you have better to limit native calls as much as you can.

W/o option 3, 1600 is not so big, as you may use this size for a motd for example.
I think [1600] vs [1600>>5] is negligeable (cpu usage) if you compare [1600] vs entity_get_XXX.

That's pretty much what the debate is about.
Is limiting native calls worth the amount of memory being used?

Arkshine 05-25-2009 16:33

Re: CPU Usage vs Memory Usage
 
I agree with Connor and Brad. But in your example using just one native (pev) I would guess it's fine too. It's not something will eat your cpu. But if you plan to use severals natives when you can avoid it for sure I would prefer to use more memory. ( at least in the case of forward called very often )

ConnorMcLeod 05-25-2009 18:02

Re: CPU Usage vs Memory Usage
 
Furthermore, if ents are not custom ents but common ents, pev_XuserX can be used by other plugins, but this is a bit unrelated.

[ --<-@ ] Black Rose 05-25-2009 18:04

Re: CPU Usage vs Memory Usage
 
ALWAYS optimize for speed.

Emp` 05-25-2009 18:23

Re: CPU Usage vs Memory Usage
 
Exolent it really comes down to what your plugin needs. For example, in one of my plugins I have literally run out of memory (even with #pragma dynamic) and am resorting to changing many things in the plugin and will be dividing it into sub-plugins.

As others have said, I don't think one native call would be that cpu intensive so I would probably opt for that method.

Exolent[jNr] 05-25-2009 18:38

Re: CPU Usage vs Memory Usage
 
Quote:

Originally Posted by Emp` (Post 834717)
in one of my plugins I have literally run out of memory

PokeMod? :mrgreen:

I was going to just go with what arkshine said, but you make a valid point, too.
Thanks everyone!

(I would +karma, but you all know what happened :roll:)


All times are GMT -4. The time now is 01:25.

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