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

Dynamic array issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-09-2012 , 23:52   Dynamic array issue
Reply With Quote #1

I'm trying to store certain properties as strings from numerous entities. To create an array for hypothetically over 100 entities would be a waste of memory. So instead, I'm trying to store multiple strings within a single dynamic array index.

I know it can be done with enum, for example:
Code:
enum _:Strings {     String1[ 32 ],     String2[ 32 ],     String3[ 32 ] } public MyFunction() {     new ArrayData[ Strings ];     //..... }
However, my issue is that the number of strings I'll be storing could vary anywhere up to say 16. Basically a dynamic array inside a dynamic array

I can't do something like this:
Code:
new ArrayData[ 16 ][ 32 ]; //put a max of 16 and a length 32 ArrayData[ 0 ] = "Some text"; ArrayData[ 1 ] = "Some more text"; ArrayData[ 2 ] = "..."; //etc. ArrayPushArray( g_Array, ArrayData );
Because the dimensions don't match.

How else can this be done? If the single array index can hold a number of strings through the use of enumerations, then surely it can be done some other way.

Thanks.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 07-09-2012 at 23:58.
hornet is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-09-2012 , 23:57   Re: Dynamic array issue
Reply With Quote #2

Sorry, I don't fully get the problem. Just be simple with it. You are trying to figure out a way to store multiple strings?
__________________
Bugsy is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-10-2012 , 00:00   Re: Dynamic array issue
Reply With Quote #3

Why don't you just store them one at a time? Or is it required that they be grouped together? Because you can't store a matrix like you store an array. (an array of strings is really a matrix of chars)
Unless pawn would allow you to store an array of pointers....but i don't think it can...

EDIT: i miss C++
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-10-2012 at 00:03.
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-10-2012 , 00:05   Re: Dynamic array issue
Reply With Quote #4

Yes I need them grouped together so when I use ArrayGetArray() I can specify which index I want, and then get them at the same time. If they were stored 1 at a time, then I'd need multiple arrays.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-10-2012 , 00:09   Re: Dynamic array issue
Reply With Quote #5

Can you store a trie in a dynamic array?
*looking that up now* Just throwing out ideas....


Yeah....no. I'm gonna shut up now.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-10-2012 at 00:18.
Liverwiz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-10-2012 , 00:23   Re: Dynamic array issue
Reply With Quote #6

Something like this? It will allow you to store NumItems strings of MaxLength length in each array.
PHP Code:

#include <amxmodx>

new Array:g_Array;

const 
NumItems 16;
const 
MaxLength 32;
const 
DataSize NumItems MaxLength;

public 
plugin_init() 
{
    
g_Array ArrayCreateDataSize );
    
    
//Store strings
    
new ArrayDataDataSize ]; 
    
copyArrayDataMaxLength ] , MaxLength "Some text" );
    
copyArrayDataMaxLength ] , MaxLength "Some more text" );
    
copyArrayDataMaxLength ] , MaxLength "..." );
    
ArrayPushArrayg_Array ArrayData );
    
    
//Retrieve strings
    
new szDataDataSize ];
    
ArrayGetArrayg_Array szData );
    
server_printszDataMaxLength ] );
    
server_printszDataMaxLength ] );
    
server_printszDataMaxLength ] );

__________________

Last edited by Bugsy; 07-10-2012 at 00:24.
Bugsy is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-10-2012 , 00:31   Re: Dynamic array issue
Reply With Quote #7

Quote:
Originally Posted by Liverwiz View Post
Can you store a trie in a dynamic array?
*looking that up now* Just throwing out ideas....


Yeah....no. I'm gonna shut up now.
Haha cheers anyway.

Quote:
Originally Posted by Bugsy View Post
Something like this? It will allow you to store NumItems strings of MaxLength length in each array.
PHP Code:

#include <amxmodx>

new Array:g_Array;

const 
NumItems 16;
const 
MaxLength 32;
const 
DataSize NumItems MaxLength;

public 
plugin_init() 
{
    
g_Array ArrayCreateDataSize );
    
    
//Store strings
    
new ArrayDataDataSize ]; 
    
copyArrayDataMaxLength ] , MaxLength "Some text" );
    
copyArrayDataMaxLength ] , MaxLength "Some more text" );
    
copyArrayDataMaxLength ] , MaxLength "..." );
    
ArrayPushArrayg_Array ArrayData );
    
    
//Retrieve strings
    
new szDataDataSize ];
    
ArrayGetArrayg_Array szData );
    
server_printszDataMaxLength ] );
    
server_printszDataMaxLength ] );
    
server_printszDataMaxLength ] );

Awsome thanks for the answer Bugsy

A question, is there a max array size? And could this solution be affected by it?
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 07-10-2012 at 00:34.
hornet is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-10-2012 , 00:33   Re: Dynamic array issue
Reply With Quote #8

Yes, if you run into problems (like seeing Run time error 3: stack error) you can try adding this to your code:
PHP Code:
#pragma dynamic 32768 
__________________

Last edited by Bugsy; 07-10-2012 at 00:34.
Bugsy is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 07-10-2012 , 00:40   Re: Dynamic array issue
Reply With Quote #9

Alright cool.

If I get issues, I could do this:
Code:
enum _:StringData {     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ],     DATA[ 32 ], }

( And then obviously use loops to fill them before pushing )
Can that be simplified somehow? Or is it a bad idea?
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-10-2012 , 00:41   Re: Dynamic array issue
Reply With Quote #10

You could, but we already know 16 * 32 isn't causing an error.
__________________
Bugsy 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 09:43.


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