3 registered members (7th_zorro, Aku_Aku, 1 invisible),
579
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Is there a way to define an array bigger than 999999?
[Re: jumpman]
#466089
05/24/17 15:24
05/24/17 15:24
|
Joined: Oct 2011
Posts: 1,082 Germany
Ch40zzC0d3r
Serious User
|
Serious User
Joined: Oct 2011
Posts: 1,082
Germany
|
This might be only true for C/C++ and not necessarily Lite-C since I didnt reverse engineer it yet: Those arrays get "allocated" depending on where you put the definition to. If its global it gets "allocated" in the .data or .rdata section of your resulting/compiled PE file. If the definition is on the stack, this data is directly allocated on the stack. Theres another way to get memory dynamicly at runtime, which is called malloc. It can allocate memory on the fly and also free it again, also you dont want the engine to save this array since you can read it yourself from a file if you need it. The engines save function is a way more complex then you might think, it has an internal structure (linked list) to keep track of all objects and there state in the game.
TL;DR: Arrays are designed for data you know the size of, if the size is by any mean dynamic you have to use malloc/free
Last edited by Ch40zzC0d3r; 05/24/17 15:26.
|
|
|
Re: Is there a way to define an array bigger than 999999?
[Re: Ezzett]
#466115
05/25/17 16:42
05/25/17 16:42
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
Thank you Ezzett, That was amazing. I looked all over my script, and saw many huge Var arrays that I made "just in case i wanted 10k entities to store vars each" and didnt realize many of these huge arrays were taking up megs!! I shortened the arrays after I tried: int* nodes; nodes = sys_malloc(huge * sizeof(int) ); //needs about 470 MB and GS gave me an error on compile saying: Wrong type P_MUL:POINTER:LONG:POINTER
|
|
|
Re: Is there a way to define an array bigger than 999999?
[Re: Ezzett]
#466120
05/25/17 19:45
05/25/17 19:45
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
My mistake. The below snippet doesnt give me errors. Did i do this right? I wanted to make it the maximum value:
int* mega_nodes;
mega_nodes = sys_malloc(2147483647*sizeof(int));
I did that not inside a function or anything, just where the other vars are declared. After doing this, can i do the following? mega_nodes[2147483647] = 2147483647? which is to go to the last slot and give it a value. A question: 1. 2147483647 x 4 = 8589934588 bytes, which comes out to 8.589 gigs! This is allocated in the GS Nexus, correct? I dont notice an increase in MB in the nexus statistics panel. I duplicated the sys_malloc with multiple different ints, each to the max int value, and my memory usage nexus-wise hasnt increased. Is this because nothing was actually stored in the array, and its just marking this memory area as "DO NOT TOUCH" for any other memory calls?
|
|
|
|