Raised This Month: $28 Target: $400
 7% 

[HELP] Optimum way to read a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
connoisseur
Senior Member
Join Date: Jan 2012
Old 03-08-2014 , 12:26   [HELP] Optimum way to read a file
Reply With Quote #1

I coded a plugin that requires to read a file which contains 50-60 steam ids.
Currently, it reads the file whenever a player connects.
Which way is optimum?
Reading the file everytime or using an array to store its contents once and reading them instead?
connoisseur is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-08-2014 , 12:31   Re: [HELP] Optimum way to read a file
Reply With Quote #2

Doing something once, or doing something multiple times?

Once. ;)
__________________
ddhoward is offline
connoisseur
Senior Member
Join Date: Jan 2012
Old 03-08-2014 , 12:40   Re: [HELP] Optimum way to read a file
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
Doing something once, or doing something multiple times?

Once. ;)
Agreed. But actually my query was something else.
Let me put it this way.
Does it take more time & cpu consumption to read a file than looping through an array?

Last edited by connoisseur; 03-08-2014 at 12:41.
connoisseur is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-08-2014 , 12:41   Re: [HELP] Optimum way to read a file
Reply With Quote #4

Yes, ridiculously so.
__________________
ddhoward is offline
Kiske
Veteran Member
Join Date: May 2009
Old 03-08-2014 , 14:14   Re: [HELP] Optimum way to read a file
Reply With Quote #5

Reading a file whenever a user connect is a poor way in this case.
You can use a trie instead of an array.
__________________

Kiske is offline
Send a message via Skype™ to Kiske
connoisseur
Senior Member
Join Date: Jan 2012
Old 03-09-2014 , 09:35   Re: [HELP] Optimum way to read a file
Reply With Quote #6

Quote:
Originally Posted by Kiske View Post
Reading a file whenever a user connect is a poor way in this case.
You can use a trie instead of an array.
Yep. Applied both trie and array combination. I saw Advanced Bans code. It was using that method.
Trie for finding the steam id, and array contained the rest of the necessary data.
connoisseur is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 03-09-2014 , 21:57   Re: [HELP] Optimum way to read a file
Reply With Quote #7

You could use TrieSetArray/TrieGetArray; https://forums.alliedmods.net/showthread.php?t=201872

Last edited by OvidiuS; 03-09-2014 at 21:58.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-10-2014 , 01:55   Re: [HELP] Optimum way to read a file
Reply With Quote #8

Quote:
Originally Posted by connoisseur View Post
Applied both trie and array combination.
Quote:
Originally Posted by OvidiuS View Post
You could use TrieSetArray/TrieGetArray
He could.



Best option could depend on content you have to store.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 02:38.


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