Raised This Month: $51 Target: $400
 12% 

[PSA] - Do not use Dynamic Variables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 12-03-2016 , 02:54   [PSA] - Do not use Dynamic Variables
Reply With Quote #1

So after some testing, Dynamic arrays are trash. are the best.

https://forums.alliedmods.net/showpo...63&postcount=7

Reference
PHP Code:
int New = 100;
int[] Hi = new int[New];

Parsing:
function(
Hi);

public 
int function(int[] Array) {

// Meme Leaks

They fail to close upon using and do not support de constructors.

ArrayLists are the way to go : ^)
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 12-11-2016 at 06:18.
OSWO is offline
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 12-03-2016 , 04:52   Re: [PSA] - Do not use Dynamic Variables
Reply With Quote #2

__________________
ImACow is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-03-2016 , 05:18   Re: [PSA] - Do not use Dynamic Variables
Reply With Quote #3

"Meme leaks" what?
klippy is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 12-03-2016 , 05:37   Re: [PSA] - Do not use Dynamic Variables
Reply With Quote #4

I used dynamic arrays in my Timer (3.0) since Checkpoints are based on the map currently played. I thought it'ld be a good idea to parse the CheckpointData (Times for each checkpoint) in a Dynamically made array

PHP Code:
int[] I_CheckpointTimes = new int[gI_TotalCheckpoints[I_ZoneGroup]];

for (
int i 0gA_CheckpointData[I_Client].Lengthi++) {
    
I_CheckpointTimes[i] = gA_CheckpointData[I_Client].Get(i);
}

sql_UpdateRecord(..., ..., I_CheckpointTimes); 
I could re-use the same ArrayList for the checkpoint in the sql_UpdateFunction but I clear the Data through a function shown:

PHP Code:
timer_PlayerFinished(I_ActivatorI_Index);

timer_StopTime(I_ActivatorI_Index); 
timer_StopTime clear's the Global, so I tried to parse through a local but Dynamic Arrays are not the way to go.

This is the proper way to go:

PHP Code:
ArrayList A_List = new ArrayList();

for (
int i 0gA_CheckpointData[I_Client].Lengthi++) {
    
A_List.Push(gA_CheckpointData[I_Client].Get(i));
}

sql_UpdateRecord(..., ..., A_List);

/// Using CloseHandle() in the function sql_UpdateRecord 
After stress testing the sql with a few recursive functions, primarily 'sql_UpdateRecord' which needed an array of CheckpointTimes. Watching the server through `htop` revealed why it crashed unexpectedly. Memory leaks through the assignment of the array and no way of disposing it. I thought you'd know what a memory leak is but ///
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 12-03-2016 at 05:48.
OSWO is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 12-03-2016 , 05:53   Re: [PSA] - Do not use Dynamic Variables
Reply With Quote #5

If there is a memory leak, and it is due to a bug in Sourcemod, then please properly file a bug report, preferably with a compilable plugin attached that demonstrates the bug. Assuming that this is intended, or that it will never be fixed, is not helpful to the community. Please also note that you have not clarified the exact version of Sourcemod that you are using, which leaves open the possibility, in our minds, that the issue you refer to is simply due to using an outdated version.

Also, my boyfriend giggled when he read "meme leaks." I thank you for your typo.
__________________

Last edited by ddhoward; 12-03-2016 at 06:10.
ddhoward is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-03-2016 , 05:54   Re: [PSA] - Do not use Dynamic Variables
Reply With Quote #6

Please provide working minimal code snippet that reproduces the issue.

Quote:
I thought you'd know what a memory leak is but ///
I know very well, it's just that you wrote "Meme leaks". My first thought was... memes. You confused me. And I just woke up.

Last edited by klippy; 12-03-2016 at 05:55.
klippy is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 12-11-2016 , 06:16   Re: [PSA] - Do not use Dynamic Variables
Reply With Quote #7

I've found the issue, the issue was not in the Dynamic arrays - but in ArrayLists. Dynamic Variables are safe hehe xd.

I was under the assumption .Resize(0) & .Clear() would truncate the memory too, but I was wrong. To fully remove memory it must be closed and re-made. Thanks to Peace-Maker for the tip.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO 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 01:34.


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