AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Pawn Memory (https://forums.alliedmods.net/showthread.php?t=106500)

Drak 10-15-2009 21:48

Pawn Memory
 
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); }

ot_207 10-16-2009 07:27

Re: Pawn Memory
 
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

vitorrd 10-16-2009 09:42

Re: Pawn Memory
 
Quote:

Originally Posted by ot_207 (Post 963648)
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?

Drak 10-16-2009 12:17

Re: Pawn Memory
 
Quote:

Originally Posted by vitorrd (Post 963706)
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)

vitorrd 10-16-2009 12:56

Re: Pawn Memory
 
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.


All times are GMT -4. The time now is 22:33.

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