Raised This Month: $ Target: $400
 0% 

CPU Usage vs Memory Usage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-25-2009 , 14:59   CPU Usage vs Memory Usage
Reply With Quote #1

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     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 05-25-2009 at 16:01.
Exolent[jNr] is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 05-25-2009 , 15:42   Re: CPU Usage vs Memory Usage
Reply With Quote #2

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.
__________________
Brad is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-25-2009 , 15:54   Re: CPU Usage vs Memory Usage
Reply With Quote #3

<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.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-25-2009 at 15:57.
ConnorMcLeod is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-25-2009 , 16:03   Re: CPU Usage vs Memory Usage
Reply With Quote #4

Quote:
Originally Posted by Brad View Post
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 View Post
<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?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-25-2009 , 16:33   Re: CPU Usage vs Memory Usage
Reply With Quote #5

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 )
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-25-2009 , 18:02   Re: CPU Usage vs Memory Usage
Reply With Quote #6

Furthermore, if ents are not custom ents but common ents, pev_XuserX can be used by other plugins, but this is a bit unrelated.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 05-25-2009 , 18:04   Re: CPU Usage vs Memory Usage
Reply With Quote #7

ALWAYS optimize for speed.
[ --<-@ ] Black Rose is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-25-2009 , 18:23   Re: CPU Usage vs Memory Usage
Reply With Quote #8

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.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-25-2009 , 18:38   Re: CPU Usage vs Memory Usage
Reply With Quote #9

Quote:
Originally Posted by Emp` View Post
in one of my plugins I have literally run out of memory
PokeMod?

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 )
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 01:25.


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