Raised This Month: $ Target: $400
 0% 

Pawn Memory


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 10-15-2009 , 21:48   Pawn Memory
Reply With Quote #1

I'm working with large strings. I read information from a file, and place it into a 2D array. (About 15 total strings). I know nothing about memory, (besides how statics work and such). My question is, below is two functions. I'm using the first one. When the function is done, is all that memory free'd up? If not, wouldn't it be better to use the second one?

Code:
#include <amxmodx> #include <cellarray> new Array:g_FinalString public plugin_init()     g_FinalString = ArrayCreate(); Function() {     new largeString[15][1024]     for(new Count;Count < 14;Count++)         formatex(largeString[Count],1023,"Random String");         // Copy "largeString" to the "g_FinalString" } Function() {     new Array:LargeString = ArrayCreate();     ArrayPushString(LargeString,"Random String");         // Copy "largeString" to the "g_FinalString"         ArrayDestroy(LargeString); }
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 10-16-2009 , 07:27   Re: Pawn Memory
Reply With Quote #2

The problem is that Array is slower than the first one, and will lag your server.
I suggest using the first one.

After Function() execution the memory will be freed after end of execution
After Function(2) execution, alloc, insert, get and after that the memory will be freed.

And as memory loss. It is basically the same.
4*15*1024 = 61440B = 60KB
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 10-16-2009 at 07:30.
ot_207 is offline
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-16-2009 , 09:42   Re: Pawn Memory
Reply With Quote #3

Quote:
Originally Posted by ot_207 View Post
The problem is that Array is slower than the first one, and will lag your server.
I suggest using the first one.

After Function() execution the memory will be freed after end of execution
After Function(2) execution, alloc, insert, get and after that the memory will be freed.

And as memory loss. It is basically the same.
4*15*1024 = 61440B = 60KB
So much for smoothness... Lag the server? No, not really.
If you know the precise size of your array, you should use the first implementation. How often is your function called?
vitorrd is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 10-16-2009 , 12:17   Re: Pawn Memory
Reply With Quote #4

Quote:
Originally Posted by vitorrd View Post
So much for smoothness... Lag the server? No, not really.
If you know the precise size of your array, you should use the first implementation. How often is your function called?
The SETTING of the array's are called only once. After that, they are received every 15 seconds.
(from g_FinalString)
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-16-2009 , 12:56   Re: Pawn Memory
Reply With Quote #5

The look-up operation is faster using the raw way, if that's not a problem. Don't worry about memory management, as long as you call a destroy function for every create function you call, it's fine.
vitorrd 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 22:33.


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