AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Most efficient way to empty a static array (https://forums.alliedmods.net/showthread.php?t=274736)

dilalmon 11-14-2015 03:56

Most efficient way to empty a static array
 
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?

Mehis 11-14-2015 04:19

Re: Most efficient way to empty a static array
 
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.

dilalmon 11-14-2015 10:13

Re: Most efficient way to empty a static array
 
Oh it's an cell array, not a string.

RedSword 11-14-2015 14:46

Re: Most efficient way to empty a static array
 
Make your own extension to use memset. I doubt you really need this though.

VoiDeD 11-15-2015 15:38

Re: Most efficient way to empty a static array
 
Quote:

Originally Posted by RedSword (Post 2363154)
Make your own extension to use memset.

Modifying plugin address space doesn't sound like good idea at all.

Quote:

Originally Posted by dilalmon (Post 2363033)
Oh it's an cell array, not a string.

What's wrong with using a loop? Are you having a measured performance impact?

Chdata 11-15-2015 16:49

Re: Most efficient way to empty a static array
 
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.

dilalmon 11-15-2015 17:35

Re: Most efficient way to empty a static array
 
Quote:

Originally Posted by VoiDeD (Post 2363518)
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.

KissLick 11-15-2015 17:54

Re: Most efficient way to empty a static array
 
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...

VoiDeD 11-15-2015 19:00

Re: Most efficient way to empty a static array
 
Quote:

Originally Posted by dilalmon (Post 2363540)
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?

RedSword 11-15-2015 21:31

Re: Most efficient way to empty a static array
 
Quote:

Originally Posted by VoiDeD (Post 2363518)
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).


All times are GMT -4. The time now is 04:54.

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