maximum size of arrays ?

Just starting out? Need help? Post your questions and find answers here.
pythagoras_156
User
User
Posts: 13
Joined: Wed Aug 20, 2003 11:08 am

maximum size of arrays ?

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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 ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Limit = upper limit of *signed* variable
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

and what are the limits ? is it explains somewhere ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Limits

Post 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,   
has-been wanna-be (You may not agree with what I say, but it will make you think).
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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
--Kale

Image
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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 :D 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...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

thanx fred for the reply :wink:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply