Raised This Month: $32 Target: $400
 8% 

Dynamic Objects and Properties - v.0.0.32 - [2018.05.08]


Post New Thread Reply   
 
Thread Tools Display Modes
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-15-2016 , 23:41   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #81

Hey, was wondering if I have to .Dispose when my plugin ends:

Code:
public void OnPluginStart()
{
    for(int i = 0; i < sizeof(gS_WeaponClasses); i++)
    {
        gD_Weapons[i] = Dynamic();
        gD_Weapons[i].SetString("weapon", gS_WeaponNames[i]);
        gD_Weapons[i].SetString("classname", gS_WeaponClasses[i]);
    }
}

public void OnPluginEnd()
{
    for(int i = 0; i < sizeof(gS_WeaponClasses); i++)
    {
        if(gD_Weapons[i].IsValid)
        {
            gD_Weapons[i].Dispose();
        }
    }
}
__________________
retired

Last edited by shavit; 07-15-2016 at 23:41.
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-15-2016 , 23:45   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #82

Affirmative.

Failure to dipose your objects results in memory leaks.
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-16-2016 , 01:29   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #83

Quote:
Originally Posted by Neuro Toxin View Post
Affirmative.

Failure to dipose your objects results in memory leaks.
I see; thanks
__________________
retired
shavit is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 07-23-2016 , 15:42   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #84

This stuff looks interesting. Imagine if we can create dynamic objects based on a JSON Schema and then parse a JSON file with validation. I tried to do something similar to this with plain keyvalue files, before the transitional syntax was announced.

I'm concerned about crashing plugins. Will this also result in memory leaks? Say a plugin creates several objects and then for some reason crashes. Then it can't dispose those objects. I suppose the Dynamic plugin could track which plugin that owns each object and watch if a plugin is unloaded and automatically dispose it.

I was just experimenting with methodmaps myself and did make a simple "class" based on StringMap. This is static objects, but my simple benchmarks shows that it reads a property/key in 70-110 nanoseconds, so it's pretty fast.
Spoiler
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 07-23-2016 at 15:43.
rhelgeby is offline
Send a message via MSN to rhelgeby
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-23-2016 , 22:12   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #85

Quote:
Originally Posted by rhelgeby View Post
This stuff looks interesting. Imagine if we can create dynamic objects based on a JSON Schema and then parse a JSON file with validation. I tried to do something similar to this with plain keyvalue files, before the transitional syntax was announced.
Currently Dynamic can read\write Flat Configs and KeyValues.

I could write a JSON interpreter, it's little trickier reading JSON compared to KeyValues.
Quote:
Originally Posted by rhelgeby View Post
I'm concerned about crashing plugins. Will this also result in memory leaks? Say a plugin creates several objects and then for some reason crashes. Then it can't dispose those objects. I suppose the Dynamic plugin could track which plugin that owns each object and watch if a plugin is unloaded and automatically dispose it.[/PHP][/SPOILER]
Very good concern.

I know that a plugins handle is parsed through a natives callback parameters. I figure I would need a way to check if a plugins handle is still valid (the plugin is loaded and running) and to find the best hook where I can iterate the object collection and Dispose objects owned by the terminated plugin.

I might focus on this sooner rather than later.
Quote:
Originally Posted by rhelgeby View Post
I was just experimenting with methodmaps myself and did make a simple "class" based on StringMap. This is static objects, but my simple benchmarks shows that it reads a property/key in 70-110 nanoseconds, so it's pretty fast.
Funny that, I just made this a few days ago for basic storage.

Before writing any code for Dynamic I had carefully planned out what I was looking to achieve. One key feature I wanted was type conversion. Using a Trie/StringMap didn't meet the criteria as it doesn't store type information (like the rest of sourcepawn). After lots of different methods the fastest method I've currently found is to use a StringMap to store an offset to the position in the array where the members data is stored. The offset cell is the members type, and the following cell(s) are the members data.

This means regardless of type usage (Get/Set Int/Float/Bool/String), Dynamic reads the actual datatype at the offset and then converts the result if required to the requested type.

I've also implemented type discovery which can read an input string and determine a safe storage type. This is used with ReadConfig/KeyValues to prevent all member types from being stored as string's internally.

So quickly going back to your JSON question. I don't believe Dynamic will require a schema as Dynamic will store member data based on it's discovered type and can safely convert any types on Get/Set if required.

Edit: I just implemented some basic garbage collection for objects owned by terminated plugins. If you know a better way to implement this (eg: a forward/hook for terminating plugins) let me know.
__________________

Last edited by Neuro Toxin; 07-23-2016 at 22:35.
Neuro Toxin is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 07-24-2016 , 02:29   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #86

There may be some purposes though where someone may want the object to remain even if their plugin crashes. Though I don't have anything in mind myself, perhaps they would want it saved for other plugins interacting with theirs, and for those to function while the crashed one reloads. Just a thought...perhaps there could be a bool setting for each plugin that defaults to clean it up on unloading or fail state, but can be set not to do so?
__________________
ThatOneGuy is offline
Chief149
Member
Join Date: Sep 2010
Old 07-24-2016 , 17:15   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #87

I seem to be getting the following error when trying to call this.GetMemberOffset in one of my dynamic classes:

[SM] Exception reported: Unable to access dynamic handle 5767256

I've traced back through the stack trace and have confirmed for certain that I was acting on a valid dynamic object.
Chief149 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-24-2016 , 19:15   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #88

Quote:
Originally Posted by ThatOneGuy View Post
There may be some purposes though where someone may want the object to remain even if their plugin crashes. Though I don't have anything in mind myself, perhaps they would want it saved for other plugins interacting with theirs, and for those to function while the crashed one reloads. Just a thought...perhaps there could be a bool setting for each plugin that defaults to clean it up on unloading or fail state, but can be set not to do so?
I completely agree. I'm tossing up between a persistent flag per object or a persistent flag per plugin.

Per object is the way I'm leaning. It's easier to implement and let's a plugin have an assortment of persistent and non-persistent objects.

Quote:
Originally Posted by Chief149 View Post
I seem to be getting the following error when trying to call this.GetMemberOffset in one of my dynamic classes:

[SM] Exception reported: Unable to access dynamic handle 5767256

I've traced back through the stack trace and have confirmed for certain that I was acting on a valid dynamic object.
Would you kindly provide the stack trace?
__________________

Last edited by Neuro Toxin; 07-24-2016 at 20:06.
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-25-2016 , 04:26   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #89

Quote:
Originally Posted by Chief149 View Post
I seem to be getting the following error when trying to call this.GetMemberOffset in one of my dynamic classes:

[SM] Exception reported: Unable to access dynamic handle 5767256

I've traced back through the stack trace and have confirmed for certain that I was acting on a valid dynamic object.
Had a bit of spare time at work.

The below is the code that throws the error in your post.

PHP Code:
    // Check if object index is valid
    
if (index || index >= s_CollectionSize)
    {
        if (
throwerror)
            
ThrowNativeError(SP_ERROR_NATIVE"Unable to access dynamic handle %d"index);
        return 
0;
    } 
This makes me believe that you're referencing an Invalid Dynamic Object. Dynamic "handles" range from 0 to approx 32K (they are internally array indices for the main collection array). You might want to check your code that is storing/retrieving the Dynamic object as something is not right.

Feel free to post code if you want me to check you're going about it right.
__________________
Neuro Toxin is offline
Chief149
Member
Join Date: Sep 2010
Old 07-25-2016 , 11:34   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #90

Well there's a little too much code to post, but here's the basics.

My plugin has two arrays:
Code:
any g_Entity[2049];
EntityType g_EntityType[2049];
When the map starts, every entity on the map is given one of my subclasses of Dynamic. Whether it be BEntity, BNpc, BDoor, etc. Every entity on the map, and every entity created later on is given an associated object and type stored in the two above arrays.

When the player presses E on an NPC for instance, the plugin does this:
Code:
int iEnt = player.GetAimTarget(); //player is a BClient, representing a Client. No problems here
if(iEnt > 0 && iEnt < 2049 && g_EntityType[iEnt] == EntityType_Npc)
{
    BNpc npc = g_Entity[iEnt];
    npc.PressE(player); //this is where the problem eventually happens
}

Last edited by Chief149; 07-25-2016 at 11:34.
Chief149 is offline
Reply


Thread Tools
Display Modes

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 10:38.


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