View Single Post
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-10-2016 , 13:37   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #132

A few tips based on your code:

Code:
public void OnPluginStart()
 {
     char[] sPath = new char[PLATFORM_MAX_PATH];
     BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-dynamic.cfg");
  
     Dynamic dStylesConfig = Dynamic();
  
     if(!dStylesConfig.ReadKeyValues(sPath))
     {
         PrintToServer("Could not read keyvalues!");
     }
  
     // .MemberCount currently requires a native call so
     // dont call it on every iteration in the loop
     // > important when code requires high performance
     int count = dStylesConfig.MemberCount;
  
     // Declare this outside the loop while using a static length.
     // When reading large data-sets, dynamically sized char arrays
     // will causes memory full errors, their memory seems to be 
     // only freed once the loop scope has been finished.
     char sName[DYNAMIC_MEMBERNAME_MAXLEN];
     
     for(int i = 0; i < count; i++)
     {
         Dynamic dStyle = dStylesConfig.GetDynamicByIndex(i);
         dStyle.GetString("name", sName, sizeof(sName));
         int iAiraccelerate = dStyle.GetInt("airaccelerate");
  
         PrintToServer("%d - %s (%d AA)", i, sName, iAiraccelerate);
  
         // These dynamic objects are disposed when the parent is disposed
         //dStyle.Dispose();
     }
     
     // Make sure you leave the disposemembers param set to true
     dStylesConfig.Dispose(true);
 }
__________________
Neuro Toxin is offline