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

Dynamically sized arrays in Pawn


Post New Thread Reply   
 
Thread Tools Display Modes
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 09-01-2015 , 13:48   Re: Dynamically sized arrays in Pawn
Reply With Quote #11

So I'm doing this
PHP Code:
enum _:myOne {
        
one,
        
two,
        
three
    
};

new 
size file_size(fileDir1);
    new 
arr = new[size];

    for(new 
0sizei++)
    
_$arr[i] = new[myOne]; 
And everything is OK. But the code below gives me a stack error. Is there any way of doing so:
PHP Code:

enum _
:myTwo {
        
_one[64],
        
_two[34],
        
_three[64]
    };

new 
size file_size(fileDir1);
    new 
arr = new[size];
    for(new 
0sizei++)
    
_$arr[i] = new[myTwo]; 

Last edited by SpeeDeeR; 09-01-2015 at 13:49.
SpeeDeeR is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-01-2015 , 16:56   Re: Dynamically sized arrays in Pawn
Reply With Quote #12

It's quite possible that you've ran out of stack/heap memory and that there's no strange error going on. You are actually allocating 162 cells for each line in a file, and you can only use about 4096 cells by default I think (probably even less because there are a few variables allocated on the stack).
What exactly are you trying to do? Please give me more code and also what exactly does your file contain when you get the stack error.

Nice to see that somebody at least tried to use this.
klippy is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 09-01-2015 , 18:53   Re: Dynamically sized arrays in Pawn
Reply With Quote #13

Quote:
Originally Posted by KliPPy View Post
What exactly are you trying to do? Please give me more code and also what exactly does your file contain when you get the stack error.
I want to replace cellarray with your dynamic array.
The stack error appears in the alloc part, file content doesn't really matter.
Edit: if you ment the lines, they are about 150.
Edit2: since I'm allocating well over 20k cells, I don't think this could work.
PHP Code:
enum _:myEnum {
        
name[64],
        
key[34],
        
action[64]
    }
    
    new 
line[256], c;
    
    new 
temp[myEnum];
    
    while(
fgets(filelinecharsmax(line))) {
        
trim(line);
        if( !(
line])
        || 
== ';'
        
|| == '/') continue;
        
        
parse(line
        
temp[name], charsmax(temp),
        
temp[key], charsmax(temp),
        
temp[action], charsmax(temp)
        );
        
        
ArrayPushArray(handletempcharsmax(temp));
    } 

Last edited by SpeeDeeR; 09-02-2015 at 14:25.
SpeeDeeR 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 19:14.


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