B4R Question Max array size

daveinhull

Active Member
Licensed User
Longtime User
Hello,

Is there a maximin size for a byte array?
I've declared a byte array of 115200 to hold 240x240x2 byte lcd bit map
But when I try to zero it with a simple loop it errors with:
Out of bounds error. Array length = 49664, Index = 49664

Why 49664, seems a strange number?

Any advice please?
 

Gerardo Tenreiro

Active Member
Licensed User
Correct if you select a "ESP32 C3" card it compiles correctly without errors
I do not have this type of card but I understand that it would work well.
I still think that the problem is within B4R so if Erel could analyze it he would give us more information.
I can only help you verify Your steps, which often helps me and eliminates installation errors and the like.
I'm sorry I can't help you more, but I'll keep an eye out to see what solutions appear.
Luck
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
@peacemaker , thanks for taking the time to test this.
I really do not understand why the variances, mine work, yours compiles but erros with a different number, and @Gerardo Tenreiro doesn't compile.
I'm sure some of this is down to the device, but I'm still not happy with the differences we are getting and the funny numbers being seen, e.g. your 102200, my 49664 and what does #CheckArrayBounds actually do?

But, I'm relly not comfortable with the the fact that in my case it works perfectly in inline C code, but fails in B4R - if B4R is only a "transcriber" then it should work in both cases given the same device???

Thanks again for your support
Dave
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Do not clone the posts, it won't help, we do not know. Only @Erel as the B4R author may have ideas here.
My guess about #CheckArrayBounds is it makes just a standard command parameter to MCU's compiler to check bounds.
No idea why C-code ignores this parameter during compilation.

If you are in a hurry with programming - just do it all in C-code, Arduino.
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Messages getting duplicated, sorry, it was my browser.....
When I refreshed m browser your messages didn't appear so I wrote my message agin and then when I posted all themessages appeared incluing my first one, again, wasn't meaning to just say it again and certainly didn't mean to be frustrated as I really appreciate your help on this.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Moreover this C-code is compiled and flashed OK šŸ¤“
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: true
#StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Public BigArray(101200) As Byte
    Public z As ULong
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Delay (3000)
    Log("AppStart")
    '
    RunNative ("LoadBigArray",Null)
'    Log ("Done in C")
'    For z = 0 To 115199
'        BigArray (z) = 0
'    Next
'    Log ("Done in B4R")
'    BigArray(87654) = 12
'    Log ("Big array value at 87654 is ",BigArray(87654))
'    BigArray(115199) = 24
'    Log ("Big array value at 115199 is ",BigArray(115199))
'    Log ("SizeOf BigArray is ", SizeOf(BigArray))
End Sub

#if c

void LoadBigArray (B4R::Object* o)
{
byte BigArray2[715200];
long z;
for (z = 0; z < 715199; z++)
{
BigArray2[z] = 0;
}
};

#End If
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
@peacemaker ,
OK thanks, so that proves that the device can handle a very big array (with no bound erros and #CheckArrayBounds = True).

Thanks for further testing and giving us (or should I say Erel) more data to work on;)
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
I tried your code, but kept the B4R included, see below, with different values of the BigArray, but in all cases the BigArray2 in the inline code was same as yours 715200.
With 715200 for BigArray in B4R - compile error, data does not fit
With 515200 for BigArray in B4R - compile error, data does not fit
With 315200 for BigArray in B4R - compile error, data does not fit
With 215200 for BigArray in B4R - compiles ok, but now the log messages are:
AppStart
Done in C
Done in B4R
Big array value at 187654 is 12
Big array value at 215199 is 24
SizeOf BigArray is 18592 <---- different number no???

In all cases the C code appears to work, i.e. no error messages, but then I don't actually log anything from within the inline code so not sure if it is behaving or not.

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: False
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Public BigArray(215200) As Byte
    Public z As ULong
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Delay (3000)
    Log("AppStart")
'   
    RunNative ("LoadBigArray",Null)
    Log ("Done in C")
    For z = 0 To 215199
        BigArray (z) = 0
    Next
    Log ("Done in B4R")
    BigArray(187654) = 12
    Log ("Big array value at 187654 is ",BigArray(187654))
    BigArray(215199) = 24
    Log ("Big array value at 215199 is ",BigArray(215199))
    Log ("SizeOf BigArray is ", SizeOf(BigArray))
End Sub

#if c

void LoadBigArray (B4R::Object* o)
{
    byte BigArray2[715200];
    long z;
    for (z = 0; z < 715199; z++)
    {
        BigArray2[z] = 0;
    }
};

#End If
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Just to check your previous code with the inline BigArray2 at 715200, I added some code to test a locaiton and return it back to B4R to log and it works
Log messages are:
AppStart
cx value is after native is 36 <---- this is correct
Done in C
Done in B4R
Big array value at 187654 is 12
Big array value at 215199 is 24
SizeOf BigArray is 18592

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: False
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Public BigArray(215200) As Byte
    Public z As ULong
    Public cx As Byte
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Delay (3000)
    Log("AppStart")
'   
    RunNative ("LoadBigArray",Null)
    Log ("cx value is after native is ",cx)
    
    Log ("Done in C")
    For z = 0 To 215199
        BigArray (z) = 0
    Next
    Log ("Done in B4R")
    BigArray(187654) = 12
    Log ("Big array value at 187654 is ",BigArray(187654))
    BigArray(215199) = 24
    Log ("Big array value at 215199 is ",BigArray(215199))
    Log ("SizeOf BigArray is ", SizeOf(BigArray))
End Sub

#if c

void LoadBigArray (B4R::Object* o)
{
    byte BigArray2[715200];
    long z;
    for (z = 0; z < 715199; z++)
    {
        BigArray2[z] = 0;
    }
    BigArray2[345678] = 36;
    b4r_main::_cx = BigArray2[345678];
};

#End If
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
@Erel ,

Sorry to direct the message directly to you, but please could you help me here. I've pretty well exhaused all the things I can think of and it's really stopped me form continuing with my small display project.

Any help would be really appreciate.

Thanks
Dave
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Just out of interest, what does c report as the size of b4r_main::_bigarray
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi @Daestrum , do you mean BigArray2 whichis teh array in the inline C code.
It reports size as 715200

Logged output is
AppStart
cx value is after native is 36
Done in C
Size of big array is 715200
Done in B4R
Big array value at 187654 is 12
Big array value at 215199 is 24
SizeOf BigArray is 18592

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: False
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Public BigArray(215200) As Byte
    Public z As ULong
    Public cx As Byte
    Public MySize As ULong
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Delay (3000)
    Log("AppStart")
'   
    RunNative ("LoadBigArray",Null)
    Log ("cx value is after native is ",cx)
    Log ("Done in C")
    Log ("Size of big array is ", MySize)

    For z = 0 To 215199
        BigArray (z) = 0
    Next
    Log ("Done in B4R")

    BigArray(187654) = 12
    Log ("Big array value at 187654 is ",BigArray(187654))
    BigArray(215199) = 24
    Log ("Big array value at 215199 is ",BigArray(215199))
    Log ("SizeOf BigArray is ", SizeOf(BigArray))
End Sub

#if c

void LoadBigArray (B4R::Object* o)
{
    byte BigArray2[715200];
    long z;
    for (z = 0; z < 715199; z++)
    {
        BigArray2[z] = 0;
    }
    b4r_main::_mysize = sizeof(BigArray2);
    BigArray2[345678] = 36;
    b4r_main::_cx = BigArray2[345678];
};

#End If
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
No I actually meant BigArray in the b4r code as in
B4X:
b4r_main::_mysize = sizeof(b4r_main::_bigarray);
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
@Daestrum , ok, sorry. It says it 4, have I got the code correct?

AppStart
cx value of BigArray2[345678] after native call is 36
Done in C
C reported size of (C) BigArray2 is 715200
C reported size of (B4R) BigArray is 4 <---- it says 4!!! - have I got the code right?
Done in B4R
Big array value at 187654 is 12
Big array value at 215199 is 24
SizeOf BigArray is 18592

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: False
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Public BigArray(215200) As Byte
    Public z As ULong
    Public cx As Byte
    Public SizeB4RBigArray As ULong
    Public SizeARDBigArray2 As ULong
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Delay (3000)
    Log("AppStart")
'   
    RunNative ("LoadBigArray",Null)
    Log ("cx value of BigArray2[345678] after native call is ",cx)
    Log ("Done in C")
    Log ("C reported size of (C) BigArray2 is ", SizeARDBigArray2)
    Log ("C reported size of (B4R) BigArray is ", SizeB4RBigArray)

    For z = 0 To 215199
        BigArray (z) = 0
    Next
    Log ("Done in B4R")

    BigArray(187654) = 12
    Log ("Big array value at 187654 is ",BigArray(187654))
    BigArray(215199) = 24
    Log ("Big array value at 215199 is ",BigArray(215199))
    Log ("SizeOf BigArray is ", SizeOf(BigArray))
End Sub

#if c

void LoadBigArray (B4R::Object* o)
{
    byte BigArray2[715200];
    long z;
    for (z = 0; z < 715199; z++)
    {
        BigArray2[z] = 0;
    }
    b4r_main::_sizeardbigarray2 = sizeof(BigArray2);
    b4r_main::_sizeb4rbigarray = sizeof(b4r_main::_bigarray);

    BigArray2[345678] = 36;
    b4r_main::_cx = BigArray2[345678];
};

#End If
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hello,

I'm just trying to put in some more test code, but getting a complier error with this
B4X:
void LoadBigArray (B4R::Object* o)
{
#if c

    byte BigArray2[215200];
    long z;
    byte a=0;
    for (z = 0; z < 215199; z++)
    {
        b4r_main::_bigarray[z] = a;
        a++;
        if (a > 255) {
            a=0;
        };
    }
};

Error is
D:\Projects\ESP Round Display\Test Max Byte Array\Test\Objects\src\b4r_main.cpp: In function 'void LoadBigArray(B4R::Object*)':
D:\Projects\ESP Round Display\Test Max Byte Array\Test\Objects\src\b4r_main.cpp:37:28: error: no match for 'operator=' (operand types are 'B4R::Array' and 'byte' {aka 'unsigned char'})
b4r_main::_bigarray[z] = a;
^
In file included from D:\Projects\ESP Round Display\Test Max Byte Array\Test\Objects\src\B4RDefines.h:24,
from D:\Projects\ESP Round Display\Test Max Byte Array\Test\Objects\src\b4r_main.cpp:1:
D:\Projects\ESP Round Display\Test Max Byte Array\Test\Objects\src\rCore.h:39:8: note: candidate: 'B4R::Array& B4R::Array::eek:perator=(const B4R::Array&)'
class Array {
^~~~~
What am I doing wrong?

Thanks
Dave
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I think the code is correct in post #34, as I think Array in b4r is a wrapper ( I will check some of my old code ). As I suspected it would return the length of a pointer.
 
Upvote 0
Top