Page 1 of 1
maximum size of arrays ?
Posted: Wed Aug 20, 2003 11:13 am
by pythagoras_156
Greetings,
I've been trying to create two big arrays in a structure and i get an error message while compiling. I'm wondering if there is a maximum limit to arrays in terms of size. This is my code :
Code: Select all
Structure MAP
maphdr.MAPHEADER
roofTile.w[10000]
floorTile.w[10000]
EndStructure
If I only create an array of 10000 short ints elements, it's ok. But creating two arrays of 10000 elements gives me an error.
Can somebody tell me what is wrong (or if there is a workaround) ?
Thanks in advance,
Pythagoras
Posted: Wed Aug 20, 2003 3:02 pm
by freak
I think the only limit to Array sizes is the avaiable memory.
However, if you use an array inside a structure, and then use that
structure inside a procedure, you have a problem.
The problem is, that local variables are allocated on the programm's
stack, which has a limited size (don't ask me how big that is). So this
could cause your problem.
A solution would be to make this Global (then it will be allocated in usual
memory) or to work around using such big Arrays inside a structure and
instead use Dim (has the same effect)
Timo
Posted: Wed Aug 20, 2003 8:40 pm
by Flype
one day i had such a problem. and it's strange as it happens randomly.
try this :
Code: Select all
#WIDTH = 1000
#HEIGHT = 1000
Structure ROW
x.l[ #WIDTH ]
EndStructure
Structure TABLE
y.row[ #HEIGHT ]
EndStructure
Procedure.l TableRead( *table.TABLE, x.l, y.l )
ProcedureReturn *table\y[ x ]\x[ y ]
EndProcedure
Procedure.l TableWrite( *table.TABLE, x.l, y.l, value.l )
oldValue.l = TableRead( *table, x, y )
*table\y[ x ]\x[ x ] = value
ProcedureReturn oldValue
EndProcedure
bobo.TABLE
Debug TableWrite( bobo, 0, 0, 79 )
Debug TableRead( bobo, 0, 0 )
Debug TableWrite( bobo, 0, 0, 56 )
Debug TableRead( bobo, 0, 0 )
It results in a MessageRequester "Purebasic - Assembler error" saying "Purebasic .asm[359] v_bobo rb -31744 error invalid value"
But if i try again and again it works.
It's as if, the first time, FASM isn't ready for such wide structure and the second or third time the compiler is prepared, informed.
Does this piece of code works on your PC ?
Posted: Wed Aug 20, 2003 8:48 pm
by dmoc
Limit = upper limit of *signed* variable
Posted: Wed Aug 20, 2003 9:22 pm
by Flype
and what are the limits ? is it explains somewhere ?
Limits
Posted: Wed Aug 20, 2003 11:40 pm
by oldefoxx
The customary limits are based on byte, word, integer, doubleword, and long integer values. In binary, these would appear as so:
Code: Select all
Byte 8 bits xxxxxxxx
Word 16 bits xxxxxxxxxxxxxxxx
integer 16 bits sxxxxxxxxxxxxxxx
(s=0, positive integer)
(s=1, negative integer)
doubleword 32 bits xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
long integer 32 bits sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(s=0, positive integer)
(s=1, negative integer)
For a bytem the largest value you can represent is 255. If you use the
upper bit as a sign bit, that is reduced to the range of -128 to 127.
a word can reach a value of 65.535. A doubleword is 65536*54436-1 in size (2*32-1), An integer of the same length is always about half that
capacity, ranging from -32,758 to 32,767 for a 16-bit integer for instance.
In many instances, design decisions as to whether to use 8 bits, 16 bits, or 32 bits force a determination as to the maximum size or range that a structure can have. Other limits are lifely to be more abritrary, perhaps based on some unit 2s or possibly some unit of tens, This is usually govern by some specific rationale, such as the overall size of the struclture and how big specific elements of it can be in order to stay within that scope. If, in this case, the overall size of the structure is the restraint, then different makeups within it, that is the number and type of fields involved, would not necessarily have any specific limit, but the sum total might generate an error if the maximum is exceeded,
Posted: Wed Aug 20, 2003 11:41 pm
by Kale
From the PB Help File:
Byte.b 1 byte in memory -128 to +127
Word.w 2 bytes in memory -32768 to +32767
Long.l 4 bytes in memory -2147483648 to +2147483647
Float.f 4 bytes in memory unlimited (see below)
String.s length of the string + 1 Up to 65536 characters
Posted: Thu Aug 21, 2003 1:00 am
by Flype
hey, lol, i know all of this !!! you didn't understand what i mean :
what is the maximum value i can pass to such allocation ?
structure
x.l[ #MAX? ] ; <----- how max can be this value
endstructure
i played sherlock holmes

and i find this :
Code: Select all
Structure WORK
a.l[ 8191 ]
EndStructure
x.WORK
Structure DONTWORK
a.l[ 8191+1 ]
EndStructure
y.DONTWORK
So, 8191 [ 0x1FFF ] seems to be the true limit but why ?
it's not a standard value, not in those well-known limits :
Byte.b 1 byte in memory -128 to +127
Word.w 2 bytes in memory -32768 to +32767
Long.l 4 bytes in memory -2147483648 to +2147483647
Float.f 4 bytes in memory unlimited (see below)
String.s length of the string + 1 Up to 65536 characters ; actually 64000-1
so... i'm wondering...
Posted: Thu Aug 21, 2003 1:16 am
by Fred
I had a problem with big structure (32k limit) which is already fixed for the next version. But think than a variable is allocated statically not dynamically, so if you plan to use this as a local variable (inside a procedure) it will probably blow the statck. Using an arrau doesn't have this limitation as it's allocated dynamically (and global variables should be ok too).
Posted: Fri Aug 22, 2003 1:55 am
by Flype
thanx fred for the reply
