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

Passing 2D array via natives


Post New Thread Reply   
 
Thread Tools Display Modes
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-12-2017 , 13:15   Re: Passing 2D array via natives
Reply With Quote #11

So you say that creating a 2d array using ArrayCreate, will allow me to take the data from that array in the second plugin only by specifying it's handle ? and all i have to do is pass the handle index from one plugin to another ?

Plugin 1
PHP Code:

new Array:g_ArrayHandle 

public plugin_init()
{
     
g_ArrayHandle ArrayCreate(641)

Plugin 2
PHP Code:
new szString[64]
ArrayGetString(g_ArrayHandleiCellszStringcharsmax(szString)) 
__________________

Last edited by Depresie; 12-12-2017 at 13:23.
Depresie is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-12-2017 , 14:17   Re: Passing 2D array via natives
Reply With Quote #12

Yes.
Plug-in 1.
PHP Code:
new Array:g_ArrayHandle ArrayCreate(641)
do_somethingg_ArrayHandle // or do_something(_:g_ArrayHandle) if "tag mismatch" 
Plug-in 2.
PHP Code:
public do_somethingidparams // native
{
  new Array:
ArrH = Array:get_param(1// Type (tag) casting, important!
  
...

__________________
My English is A0

Last edited by E1_531G; 12-12-2017 at 14:19.
E1_531G is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-12-2017 , 14:46   Re: Passing 2D array via natives
Reply With Quote #13

Another bad solution is to make 2 natives:
-something that will send to the main plugin how many strings you have in the array. Let's say x
-then the main plugin will receive x native calls, each pushing one string, and adding them to a 2d array
__________________
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-12-2017 , 15:15   Re: Passing 2D array via natives
Reply With Quote #14

What do you think it would be better in performance ?

I.
1. Creating a Dynamic Array
2. Pass the handle through native
3. Retrieve data from the Dynamic Array using the handle


II.
1. Creating an 1024 size array
2. copy all the strings in it with a special char at the beginning of each
3. Loop through 1024 cells, to find the cells that match the special char
5. Then copy the strings into a 2d array
__________________

Last edited by Depresie; 12-12-2017 at 15:16.
Depresie is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-12-2017 , 15:51   Re: Passing 2D array via natives
Reply With Quote #15

Of course number I.
Handler is only one int number, not 1024 cells.
Also, CellArray works at the module level, which is a bit faster than the plugin level.
__________________
My English is A0

Last edited by E1_531G; 12-12-2017 at 15:51.
E1_531G 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 12:53.


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