error if array bigger than 2 Gb on a 64 bit system

Windows specific questions.
Post Reply
fifoul
Posts: 15
Joined: Oct 17, 2005 13:20
Location: France

error if array bigger than 2 Gb on a 64 bit system

Post by fifoul »

Hello,

I try to create a big array with 3 dimensions but when i compile the code, an error appears

I don't undestand why ?

I use :
FreeBASIC-1.09.0-winlibs-gcc-9.3.0
FBIde0.4.6r4

The compiler path is : C:\FreeBasic\fbc64.exe
The compiler command is : "<$fbc>" "<$file>" -arch x86-64

Code:

Code: Select all

'----------------------------------------------------------

dim as integer x,y,z

const xmax = 2000
const ymax = 2000
const zmax = 70

dim shared as single arraya(zmax,ymax,xmax)
dim shared as single arrayb(zmax,ymax,xmax)

screenres 800,600,32

for z=0 to zmax
 for y=0 to ymax
  for x=0 to xmax   
   arraya(z,y,x)=1.234
   arrayb(z,y,x)=5.678
  next
 next
next 

? arraya(2,2,2)
? arrayb(2,2,2)

sleep

'--------------------------------------------------------------
Command executed:
"C:\FreeBasic\fbc64.exe" "C:\Users\roberto\Desktop\test limit mem.bas" -arch x86-64

Compiler output:
C:\FreeBasic\lib\win64\crt2.o: in function `__tmainCRTStartup':
R:\winlibs64-sjlj-9.3.0\mingw-w64-v7.0.0\mingw-w64-crt/crt/crtexe.c:259:(.text+0x1cd): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_Sleep' defined in .idata$5 section in C:\FreeBasic\lib\win64/libkernel32.dll.a(dclps01409.o)
R:\winlibs64-sjlj-9.3.0\mingw-w64-v7.0.0\mingw-w64-crt/crt/crtexe.c:286:(.text+0x25a): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_SetUnhandledExceptionFilter' defined in .idata$5 section in C:\FreeBasic\lib\win64/libkernel32.dll.a(dclps01393.o)
R:\winlibs64-sjlj-9.3.0\mingw-w64-v7.0.0\mingw-w64-crt/crt/crtexe.c:294:(.text+0x288): relocation truncated to fit: R_X86_64_PC32 against symbol `__mingw_winmain_hInstance' defined in COMMON section in C:\FreeBasic\lib\win64\crt2.o
R:\winlibs64-sjlj-9.3.0\mingw-w64-v7.0.0\mingw-w64-crt/crt/crtexe.c:320:(.text+0x2ec): relocation truncated to fit: R_X86_64_PC32 against symbol `__mingw_winmain_lpCmdLine' defined in COMMON section in C:\FreeBasic\lib\win64\crt2.o
R:\winlibs64-sjlj-9.3.0\mingw-w64-v7.0.0\mingw-w64-crt/crt/crtexe.c:246:(.text+0x465): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_GetStartupInfoA' defined in .idata$5 section in C:\FreeBasic\lib\win64/libkernel32.dll.a(dclps00742.o)
C:\FreeBasic\lib\win64/libfb.a(init.o):init.c:(.text+0x2): relocation truncated to fit: R_X86_64_PC32 against `.bss'
C:\FreeBasic\lib\win64/libfb.a(init.o):init.c:(.text+0xb): relocation truncated to fit: R_X86_64_PC32 against `.bss'
C:\FreeBasic\lib\win64/libfb.a(init.o):init.c:(.text+0x21): relocation truncated to fit: R_X86_64_PC32 against symbol `__fb_ctx' defined in COMMON section in C:\FreeBasic\lib\win64/libfb.a(init.o)
C:\FreeBasic\lib\win64/libfb.a(init.o):init.c:(.text+0x52): relocation truncated to fit: R_X86_64_PC32 against `.bss'
C:\FreeBasic\lib\win64/libfb.a(init.o):init.c:(.text+0x73): relocation truncated to fit: R_X86_64_PC32 against symbol `__fb_ctx' defined in COMMON section in C:\FreeBasic\lib\win64/libfb.a(init.o)
C:\FreeBasic\lib\win64/libfb.a(init.o):init.c:(.text+0x84): additional relocation overflows omitted from the output

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win64 (64bit)
OS: Windows NT 6.2 (build 9200)
Last edited by fxm on Mar 25, 2023 12:01, edited 1 time in total.
Reason: Added code tags.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: error if array bigger than 2 Gb on a 64 bit system

Post by fxm »

You must declare dynamic arrays (the memory used by a dynamic array to store its elements is allocated at run-time in the heap).
For example:

Code: Select all

redim shared as single arraya(zmax,ymax,xmax)
redim shared as single arrayb(zmax,ymax,xmax)
fifoul
Posts: 15
Joined: Oct 17, 2005 13:20
Location: France

Re: error if array bigger than 2 Gb on a 64 bit system

Post by fifoul »

Thank you very much FXM, it works!
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: error if array bigger than 2 Gb on a 64 bit system

Post by fxm »

For a fixed-length array, the data is either allocated on the program stack, or in the .BSS/.DATA section of the executable depending on whether this array was declared with Static (or Shared).

For a variable-length array:
- only the array descriptor is either allocated on the program stack, or in the .BSS/.DATA section of the executable depending on whether this array was declared with Static (or Shared),
- on the other hand the array elements are always allocated in the heap.
Post Reply