Page 1 of 1
ReDim : Array not initialized
Posted: Thu Mar 07, 2024 4:03 pm
by Otrebor
Hi
I do not know if this is related with my PC or...
Code: Select all
Dim frameInValues.u (250000,0)
ReDim frameInValues.u (250000,1949)
ReDim frameInValues.u (250000,1950);----> Variable Viewer: The Array is not initialized
Code: Select all
Dim frameInValues.u (250000,0)
ReDim frameInValues.u (250000,10)
ReDim frameInValues.u (250000,1950);------>Variable Viewer: This is OK
Code: Select all
Dim frameInValues.u (250000,3000); ------>Variable Viewer: This is OK
OS: WIN 10
PB 6.01 LTS and PB 6.1 Beta 4 (both x86) asm or c - not tested with last beta
Re: ReDim : Array not initialized
Posted: Thu Mar 07, 2024 4:30 pm
by RASHAD
PB 6.04 x86 or x64 Windows 11 x64
No problem
Re: ReDim : Array not initialized
Posted: Thu Mar 07, 2024 4:36 pm
by Otrebor
Thanks, RASHAD!
Re: ReDim : Array not initialized
Posted: Thu Mar 07, 2024 4:45 pm
by NicTheQuick
An Unicode array of the dimensions (250000, 1949) has 487,501,950 entries and allocates 975,003,900 bytes (~930 MiB) of memory.
If you make it bigger your operating system may has trouble to simply enlarge the memory when it can not find enough free memory directly behind the currently allocated space in memory.
If this is the case it has to allocate a completely new memory block of the target size and copying over the data from the old to the new location in memory. During this process your program consumes more than twice the amount of memory. And if there is not enough memory left the ReDim operation simply fails.
That might be the reason why your first example does not work but the other ones do.
Here's my calculation of the worst case memory consumption of your examples:
Example1: ((250000 + 1) · (1949 + 1) + (250000 + 1) · (1950 + 1)) · 2 bytes = 1,950,507,802 bytes = 1,860.15 MiB
Example2: ((250000 + 1) · (10 + 1) + (250000 + 1) · (1950 + 1)) · 2 bytes = 981,003,924 bytes = 935.56 MiB
Example3: (250000 + 1) · (3000 + 1) · 2 bytes = 1,500,506,002 bytes = 1,430.99 MiB
Re: ReDim : Array not initialized
Posted: Thu Mar 07, 2024 4:46 pm
by STARGÅTE
No problem here.
The issue could be related to your system.
In the first case ReDim frameInValues.u (250000,1949) allocates around 1 GB.
If you then resize the array and the memory do not fit at the current position, PureBacis allocates another 1 GB for the new array and copy all data. You need 2 GB space.
In the second case, the initial array is very small, and only 1 GB is needed.
In the third case, you also need only 1.5 GB.
Edit: Nic was faster ^^
Re: ReDim : Array not initialized
Posted: Thu Mar 07, 2024 5:18 pm
by Otrebor
Thanks, NicTheQuick and STARGÅTE for the explanation!