AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Dynamic Objects and Properties - v.0.0.32 - [2018.05.08] (https://forums.alliedmods.net/showthread.php?t=270519)

Neuro Toxin 08-22-2015 20:34

Dynamic Objects and Properties - v.0.0.32 - [2018.05.08]
 
Dynamic Wiki | Download | Examples

Dynamic allows developers to use truly dynamic data structures in SourcePawn.
This means you can define a Methodmap and use Dynamic to back it's member data at run-time.
All dynamic members are typed which allows automatic type conversion between base types.

You can then extend and inherit Dynamic Methodmaps to build complex namespaces.
Namespaces simplify the sharing of complex structures which third party plugins can easily access with a minimal amount of code.


Features
- Fully methodmap based to try and give an Object Orientated feel
- Inherit Dynamic to make your own simple methodmaps
- Easily name and retrieve dynamic objects between multiple plugins (no natives required)!!!!
- Supports String, int, float, bool, Handle, Vector and Dynamic types
- Automatic type conversion!!
- Static objects for Server and Player Settings
- Hook member changes
- Member iteration / looping
- Member sorting
- Load and Save flat configs
- Load and Save KeyValue configs


Dynamic Methodmaps
- Extend Dynamic to create your own Dynamic methodmaps
- A Class Builder to quickly generate basic Dynamic methodmaps
- You dont have to muck around with Dynamic Member Offsets to improve performance
- All of the same features that come with Dynamic Objects

Planned Changes
- Add serialisation support using mysql

Download (v0.0.32)
Example Use + Features
Example Class Use Example
Class Example
Class Builder
Include File

SM9 08-23-2015 07:03

Re: Dynamic Objects and Properties
 
Very cool, Will save me a lot of time instead of using natives all the time :P

Neuro Toxin 08-26-2015 23:38

Re: Dynamic Objects and Properties
 
I've done some profiling of the current version attached to the OP.

Here is the profiling code:

Spoiler
The outputs are below for 3 runs:

Code:

[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.003906 second(s)
Created 99000 dynamic member(s) in 1.492187 second(s)
Read 99000 dynamic member(s) in 0.527343 second(s)
Verified 99000 dynamic member(s) in 2.871093 second(s)
Updated 99000 dynamic member(s) in 0.542968 second(s)
Disposed 1000 dynamic object(s) in 0.011718 second(s)

[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.003906 second(s)
Created 99000 dynamic member(s) in 1.460937 second(s)
Read 99000 dynamic member(s) in 0.531250 second(s)
Verified 99000 dynamic member(s) in 2.839843 second(s)
Updated 99000 dynamic member(s) in 0.546875 second(s)
Disposed 1000 dynamic object(s) in 0.011718 second(s)

[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.000000 second(s)
Created 99000 dynamic member(s) in 1.492187 second(s)
Read 99000 dynamic member(s) in 0.527343 second(s)
Verified 99000 dynamic member(s) in 2.863281 second(s)
Updated 99000 dynamic member(s) in 0.546875 second(s)
Disposed 1000 dynamic object(s) in 0.011718 second(s)


Neuro Toxin 08-26-2015 23:57

Re: Dynamic Objects and Properties
 
1 Attachment(s)
I've made a second version.

The main idea was to try and speed up Create/Update member operations.

The internal data for each object is one array, rather than 3 arrays (one for each type (int, float, string)).

The member name is also contained in the data, where as the first version has a lookup array that points to the members position in the data array (1 per type again).

Code:

[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.000000 second(s)
Created 99000 dynamic member(s) in 2.285156 second(s)
CRASHED FOR TAKING TO LONG LOL

The benchmarks are considerably slower in this version. I think this is because the lookups per type in the first version are not looping the whole member set on each request.

I also believe lots of the internal functions are passing around arguments that could be static.

Version 002 is attached to this post.

If anyone has any idea's or suggestions on how to go about making this as optimised as possible, I'm all ears!

zipcore 08-27-2015 23:00

Re: Dynamic Objects and Properties
 
Cool stuff

headline 08-28-2015 00:06

Re: Dynamic Objects and Properties
 
Quote:

Originally Posted by zipcore (Post 2337583)
cool stuff

he is back boys

Neuro Toxin 08-28-2015 00:12

Re: Dynamic Objects and Properties
 
Quickly. Get him before he leaves lol

Edit: on topic. I done another version which is heaps faster!

Neuro Toxin 08-28-2015 04:39

Re: Dynamic Objects and Properties
 
1 Attachment(s)
Version 003.

I'm using a Trie for member lookups and arrays for data storage. It's up to 10 times faster.

The Trie holds the offset for where the members data is held in the internal array.

Code:

[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.000000 second(s)
Created 99000 dynamic member(s) in 0.164062 second(s)
Read 99000 dynamic member(s) in 0.113281 second(s)
Verified 99000 dynamic member(s) in 0.277343 second(s)
Updated 99000 dynamic member(s) in 0.125000 second(s)
Disposed 1000 dynamic object(s) in 0.007812 second(s)

[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.000000 second(s)
Created 99000 dynamic member(s) in 0.164062 second(s)
Read 99000 dynamic member(s) in 0.109375 second(s)
Verified 99000 dynamic member(s) in 0.265625 second(s)
Updated 99000 dynamic member(s) in 0.128906 second(s)
Disposed 1000 dynamic object(s) in 0.007812 second(s)

[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.000000 second(s)
Created 99000 dynamic member(s) in 0.164062 second(s)
Read 99000 dynamic member(s) in 0.109375 second(s)
Verified 99000 dynamic member(s) in 0.273437 second(s)
Updated 99000 dynamic member(s) in 0.125000 second(s)
Disposed 1000 dynamic object(s) in 0.011718 second(s)


aeleos 09-03-2015 00:52

Re: Dynamic Objects and Properties
 
Wow thank you for this, this is exactly what I have been needing for my plugin. I am correct in saying it works just like any other data type in that I can have an array of them like
Code:

Dynamic object[32]

Neuro Toxin 09-03-2015 01:44

Re: Dynamic Objects and Properties
 
You sure can :)

Edit: remember to initialise them as per the first post


All times are GMT -4. The time now is 06:16.

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