Raised This Month: $ Target: $400
 0% 

[INC] HFile - Hirsw0w's Files


Post New Thread Reply   
 
Thread Tools Display Modes
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 07-21-2014 , 22:48   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #11

Quote:
Originally Posted by Neeeeeeeeeel.- View Post
You are right
Btw the output will still be 0.000000
get_gametime would not show the difference, it has nothing to do with unixtime or anything else, use Float:engfunc(EngFunc_Time)
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-22-2014 , 03:15   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #12

Your code is quite horrible, unsafe and with mistakes, and talking about speed is irrelevant for such things as most includes uses new file natives too.
I would not recommend people to use this.
__________________

Last edited by Arkshine; 07-22-2014 at 03:21.
Arkshine is offline
Hirsw0w
Junior Member
Join Date: Jul 2014
Old 07-22-2014 , 04:19   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #13

Quote:
Originally Posted by Arkshine View Post
Your code is quite horrible, unsafe and with mistakes, and talking about speed is irrelevant for such things as most includes uses new file natives too.
I would not recommend people to use this.
what your minining unsafe? and what the nw file natives? I change all the include for them and improve the speed and more if you can explain yourself more I be happy.
Hirsw0w is offline
Strick3n
Member
Join Date: Apr 2013
Old 07-22-2014 , 04:26   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #14

Quote:
Originally Posted by Arkshine View Post
Your code is quite horrible, unsafe and with mistakes, and talking about speed is irrelevant for such things as most includes uses new file natives too.
I would not recommend people to use this.
trash this shit, this inc is useless as you said, so trash it.
better to use the original file.inc natives.
Strick3n is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-22-2014 , 05:11   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #15

  • You pass a buffer size instead of buffer size - 1 -> potential overflow issue.
  • There is macro charsmax to use sizeof array - 1, use it.
  • Hardcoding limit sucks.
  • Calling 2 replace_all with ^r/^n is not needed. Buffer should not contain that.
  • Calling write_file in a loop is really bad. Did you check its source code? This native is about openinp/closing/buffering a file.
  • This feels unnecessary to call file_exists when you can check with fopen below.
  • new tmpres[128]: This is rather small buffer.
  • You read lines with a buffer of 128 and you write line with a buffer of 150, logic?
  • What about if file exists but can't be opened?
  • Always trim your buffer as it can contains spaces.
  • No point to use strlen when you can get length from fgets return value.
  • Why this does assume format will be "something = value"?
  • Checking if an array is empty with strlen is overkill, just check [0].
  • Getting a file size, file_size should do the same.

You have already better API around here, which are more complete, tested, and safe.
Speed doesn't matter, you are not going to call such API 10000 times anyway, but yours is really poorly coded.
__________________

Last edited by Arkshine; 07-22-2014 at 05:53.
Arkshine is offline
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 07-22-2014 , 09:07   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #16

Quote:
Originally Posted by meTaLiCroSS View Post
get_gametime would not show the difference, it has nothing to do with unixtime or anything else, use Float:engfunc(EngFunc_Time)
As far as I remember, get_gametime returns a float. If it does my code works. When I mentioned unixtime o.O

For example:
PHP Code:
new Float:startTime get_gametime(); // let's say get_gametime() it's equal to 25.634
// do stuff
new Float:endTime get_gametime(); // let's say that endTime it's equal to 28.453
new Float:doStuffTime endTime-startTime;
//doStuffTime will be "do stuff" execute delay, in this case: 2.819 
PS: My theory will be shit if get_gametime returns an int
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
Strick3n
Member
Join Date: Apr 2013
Old 07-22-2014 , 14:55   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #17

Quote:
Originally Posted by Arkshine View Post
  • You pass a buffer size instead of buffer size - 1 -> potential overflow issue.
  • There is macro charsmax to use sizeof array - 1, use it.
  • Hardcoding limit sucks.
  • Calling 2 replace_all with ^r/^n is not needed. Buffer should not contain that.
  • Calling write_file in a loop is really bad. Did you check its source code? This native is about openinp/closing/buffering a file.
  • This feels unnecessary to call file_exists when you can check with fopen below.
  • new tmpres[128]: This is rather small buffer.
  • You read lines with a buffer of 128 and you write line with a buffer of 150, logic?
  • What about if file exists but can't be opened?
  • Always trim your buffer as it can contains spaces.
  • No point to use strlen when you can get length from fgets return value.
  • Why this does assume format will be "something = value"?
  • Checking if an array is empty with strlen is overkill, just check [0].
  • Getting a file size, file_size should do the same.

You have already better API around here, which are more complete, tested, and safe.
Speed doesn't matter, you are not going to call such API 10000 times anyway, but yours is really poorly coded.
Why you don't trash it yet?
Strick3n is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 07-22-2014 , 15:46   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #18

Quote:
Originally Posted by Neeeeeeeeeel.- View Post
As far as I remember, get_gametime returns a float. If it does my code works. When I mentioned unixtime o.O

For example:
PHP Code:
new Float:startTime get_gametime(); // let's say get_gametime() it's equal to 25.634
// do stuff
new Float:endTime get_gametime(); // let's say that endTime it's equal to 28.453
new Float:doStuffTime endTime-startTime;
//doStuffTime will be "do stuff" execute delay, in this case: 2.819 
PS: My theory will be shit if get_gametime returns an int
Do you know what it returns get_gametime() ? It's a member of a global variable which changes on specific functions on the engine, you can cache get_gametime() value and execute billion of loops, and at the end, get_gametime() will return the same number as the cached above.

engfunc(EngFunc_Time) (Sys_FloatTime()) returns the seconds elapsed since the game started, and it's like using get_systime() but in float.

If being too easy as you said, why do you think that this guy created this?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-23-2014 , 01:00   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #19

Quote:
Originally Posted by meTaLiCroSS View Post
Do you know what it returns get_gametime() ? It's a member of a global variable which changes on specific functions on the engine, you can cache get_gametime() value and execute billion of loops, and at the end, get_gametime() will return the same number as the cached above.

engfunc(EngFunc_Time) (Sys_FloatTime()) returns the seconds elapsed since the game started, and it's like using get_systime() but in float.

If being too easy as you said, why do you think that this guy created this?
Or use tickcount().
__________________
Black Rose is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 07-23-2014 , 15:39   Re: [INC] HFile - Hirsw0w's Files
Reply With Quote #20

Quote:
Originally Posted by Black Rose View Post
Or use tickcount().
I was going to edit it, but I knew that you'll post it, I saw it on your test plugin of your A* Pathfinder plugin
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS 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 15:52.


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