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

Most efficient way to empty a static array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dilalmon
AlliedModders Donor
Join Date: Apr 2013
Old 11-14-2015 , 03:56   Most efficient way to empty a static array
Reply With Quote #1

What would be the most efficient way to empty (zero out) a static array of 256?
Surely there must be a way to do it without going through a loop?
dilalmon is offline
Mehis
Senior Member
Join Date: Mar 2013
Location: basement
Old 11-14-2015 , 04:19   Re: Most efficient way to empty a static array
Reply With Quote #2

PHP Code:
strcopyszBuffersizeofszBuffer ), "" ); 

Although, if you're printing something you could do something like this.

PHP Code:
char sz[6];
sz[0] = 'H';
sz[1] = 'e';
sz[2] = 'y';
sz[3] = '\0'
sz[4] = '!';

PrintToServer"Msg: %s"sz ); // Prints 'Hey' instead of 'Hey!' 
I wouldn't recommend it and there really isn't any reason to do it.

Last edited by Mehis; 11-14-2015 at 06:34.
Mehis is offline
dilalmon
AlliedModders Donor
Join Date: Apr 2013
Old 11-14-2015 , 10:13   Re: Most efficient way to empty a static array
Reply With Quote #3

Oh it's an cell array, not a string.
dilalmon is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 11-14-2015 , 14:46   Re: Most efficient way to empty a static array
Reply With Quote #4

Make your own extension to use memset. I doubt you really need this though.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 11-14-2015 at 14:47.
RedSword is offline
VoiDeD
AlliedModders Donor
Join Date: Mar 2009
Location: Illinois, USA
Old 11-15-2015 , 15:38   Re: Most efficient way to empty a static array
Reply With Quote #5

Quote:
Originally Posted by RedSword View Post
Make your own extension to use memset.
Modifying plugin address space doesn't sound like good idea at all.

Quote:
Originally Posted by dilalmon View Post
Oh it's an cell array, not a string.
What's wrong with using a loop? Are you having a measured performance impact?
__________________
VoiDeD is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 11-15-2015 , 16:49   Re: Most efficient way to empty a static array
Reply With Quote #6

Make up some value to use as a terminator and stop whatever you're doing when you come across it, and otherwise only initialize it once.... depending on what you're actually trying to do.
__________________
Chdata is offline
dilalmon
AlliedModders Donor
Join Date: Apr 2013
Old 11-15-2015 , 17:35   Re: Most efficient way to empty a static array
Reply With Quote #7

Quote:
Originally Posted by VoiDeD View Post
What's wrong with using a loop? Are you having a measured performance impact?
Yeah, I'm getting some micro-freezes for clearing an array[1024] 64 times.
This is called every frame.
dilalmon is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-15-2015 , 17:54   Re: Most efficient way to empty a static array
Reply With Quote #8

Well, then I suggest some kind of "stopper" (or variable with last valid index) like Chdata said.
Every array clearing will give you micro-freezes if you do it 64x per frame...
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
VoiDeD
AlliedModders Donor
Join Date: Mar 2009
Location: Illinois, USA
Old 11-15-2015 , 19:00   Re: Most efficient way to empty a static array
Reply With Quote #9

Quote:
Originally Posted by dilalmon View Post
Yeah, I'm getting some micro-freezes for clearing an array[1024] 64 times.
This is called every frame.
That sounds very suspicious, clearing 65k cells should take nanoseconds at best. How do you know your perf issues are being caused by your loops?
__________________
VoiDeD is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 11-15-2015 , 21:31   Re: Most efficient way to empty a static array
Reply With Quote #10

Quote:
Originally Posted by VoiDeD View Post
Modifying plugin address space doesn't sound like good idea at all.
I didn't say that; I meant to also declare the variable needed (to be zero'ed out) in that extension. And as I said, I doubt this should be needed.

I'd believe there is a plugin architecture problem here (but not enough information is given).
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword is offline
Reply


Thread Tools
Display Modes

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 11:48.


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