Results 1 to 10 of 25

Thread: Maximum width of canvas = 1348921, but why?

Hybrid View

  1. #1

    Maximum width of canvas = 1348921, but why?

    OK, here I am with my silly virtual canvas questions again.

    Here is a sample program:
    Uses "UI"
    Uses "OS"       
    Uses "GDIP"                
    
    '---Constant declarations
    Begin ControlID  
      %ID_Canvas,
    End ControlID
    
    %CANVAS_LENGTH            = 1348921       ' Width of graph in pixels
    %CANVAS_HEIGHT            = 380           ' Height of graph in pixels
    %VP_WIDTH                 = 1000          ' Width, in pixels, of viewport into canvas
          
    '------------------------------------------------------------------------------
    ' Program start point
    '------------------------------------------------------------------------------
    Function TBMain() As Long
      Local hDlg    As DWord   '---Used to store window handle of main dialog
      
      '---Create a new dialog
      hDlg = Dialog_New Pixels, 0, "Canvas Test", -1, -1, 1020, 420,
                                                      %WS_DLGFRAME  | 
                                                      %DS_CENTER    | 
                                                      %WS_CAPTION   | 
                                                      %WS_SYSMENU   | 
                                                      %WS_OVERLAPPEDWINDOW
    
        
      '---Show dialog in modal mode
      '---cbDialog function is the callback function handling dialog events
      '---Application control will pass to dialog callback till dialog will exists 
        Dialog Show Modal hDlg, Call cbDialog
    
    End Function 
    
    '------------------------------------------------------------------------------
    ' Callback procedure for main window
    '------------------------------------------------------------------------------
    CallBack Function cbDialog() As Long
      Select Case CBMSG
        
        Case %WM_INITDIALOG
          Local i As Long
          
          '---Add controls
          Control Add Canvas,  CBHNDL, %ID_Canvas, "", 10, 10, %VP_WIDTH, %CANVAS_HEIGHT + 20, %WS_BORDER | %WS_CHILD | %WS_VISIBLE | %SS_NOTIFY, Call cbDialog
                                  
          Canvas_Attach(CBHNDL, %ID_Canvas, TRUE)
          ' Set the canvas to be very wide (virtualy)
          Canvas_SetVirtual(%CANVAS_LENGTH, %CANVAS_HEIGHT)
          Canvas_SetView(0, 0)
    
          ' Write something on the canvas so we can know when it moves
          For i = 1 To %CANVAS_LENGTH Step 100
            Canvas_SetPos(i, 100)
            Canvas_Print(i)
          Next i
                      
      End Select
    
    End Function
    
    Now, if you run this program, it will work just fine. You can use the thumb to drag the canvas underneath the viewport, and you can see all of the numbers (showing that you have access to the whole canvas).

    But if you use %CANVAS_LENGTH = 1348922 (just one more than is in the program above) then it will not work. The canvas will not scroll around, and you can't see any more of the numbers.

    But why? My computer has tons of RAM (32GB). Could it be possible to use canvases that are much, much bigger than this? (say 21600000 pixels wide) I have 250 data points coming in from my embedded system every second, and I'd like to be able to graph 24 hours of data on one canvas.

    Everything works wonderfully up to 1348921.

    I think it has to do with the total size (area) of the canvas, because if I reduce the canvas height I can increase the width.

    Is it because 1348922 * 380 * 4 is getting close to 2^31?

    *Brian

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,281
    Blog Entries
    2
    Rep Power
    10
    A lot of data.

    Yes, problem is allocated memory.
    thinBasic is a 32bit application and has the limit of 2GB per process. Even if you have plenty of memory, every 32bit process has this limit.

    You need to find another strategy.
    You need to have data stored somewhere, show some rolling screen that shows only the last x minutes.
    When you need to show the whole day or more, reload data and show them.
    To store data you can use new SQLite module and manage a local DB where to put all the data you get.

    A quick and dirty way to go further the limit of 1348921 pixels wide is to reduce the height of the Canvas.
    Set
    %CANVAS_HEIGHT = 100 (for example) and you will be able to set a much bigger %CANVAS_LENGTH.
    Last edited by ErosOlmi; 08-02-2018 at 17:03.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    Ahh! Very good. That makes complete sense. Thank you.

    Expanding the canvas was just my lazy attempt at getting more recording time. I will have to bite the bullet and do things right!

    What are the limits to arrays? Can I, for example, have a long array that has 1073741823 elements (2GB in size)? Or do all variables in a TB program together need to fit into 2GB?

    *Brian

  4. #4
    what about 2 canvases !!! when the graphics reaches the end of the first wide canvas it begins to plot to the second canvas.

    i don't want to cover your last question, here it is again since it is important:
    What are the limits to arrays? Can I, for example, have a long array that has 1073741823 elements (2GB in size)? Or do all variables in a TB program together need to fit into 2GB?

    *Brian
    Uses "UI"
    
    Dim x,y As Double
    
    Begin ControlID
    %ID_Canvas
    %ID_Canv2
    End ControlID
    
    Function TBMain() As Long
    Local hDlg As DWord '---Used to store window handle of main dialog
    
    hDlg = Dialog_New Pixels, 0, "canvas wide graphics ", -1, -1, 1200, 775,
    %WS_DLGFRAME | 
    %DS_CENTER | 
    %WS_CAPTION | 
    %WS_SYSMENU | 
    %WS_OVERLAPPEDWINDOW
    
    Dialog Show Modal hDlg, Call cbDialog
    End Function
    
    CallBack Function cbDialog() As Long
    Select Case CBMSG
    Case %WM_INITDIALOG
    Control Add Canvas, CBHNDL, %ID_Canvas, "", 50, 10,1000, 200, %WS_BORDER | %WS_CHILD | %WS_VISIBLE
    Control Add Canvas, CBHNDL, %ID_Canv2, "", 50, 210,1000, 200, %WS_BORDER | %WS_CHILD | %WS_VISIBLE
    Canvas_Attach(CBHNDL, %ID_Canvas, %TRUE)
    Canvas_SetVirtual(1000, 380)
    Canvas_SetView(0,0) 
    Canvas_Width(2)
    Canvas_Clear %BLACK 
    Canvas_SetView(1000,0) 
    
    'Canvas_Scale(-20, -5, 20, 20) 
    
    For x = 0 To 2000 Step 0.1
    
    y = Sin(x)*20* Rndf(1, 2)*Sin(x/3)^2
    
    Canvas_Width(3)
    
    Canvas_Line( (x*10, y +100), (x*10, y +100) , Rgb(255, 255, 0) )
    
    Canvas_Redraw
    
    Next
    
    ''''wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
    Canvas_Attach(CBHNDL, %ID_Canv2, %TRUE)
    Canvas_SetVirtual(1000, 380)
    Canvas_SetView(0,0) 
    Canvas_Width(2)
    Canvas_Clear %BLACK 
    Canvas_SetView(1000,0) 
    
    'Canvas_Scale(-20, -5, 20, 20)
    'mark the beginning of canvas 2 graphics with a circle 
    Circle(10,70,10,Rgb(0,255,0),Rgb(255,0,0))
    For x = 0 To 2000 Step 0.1
    
    y = Sin(x)*20
    
    Canvas_Width(3)
    
    Canvas_Line( (x*10, y +100), (x*10, y +100) , Rgb(255, 255, 0) )
    Canvas_Redraw
    Next
    End Select
    End Function 
    
    Function Circle(x As Long, y As Long, r As Long, colr, colrFill) 
       Canvas_Ellipse(x-r, y-r, x+r, y+r, colr, colrFill)
    End Function
    
    Last edited by primo; 08-02-2018 at 16:19.

  5. #5
    As an aside, for anybody who's interested:

    One of the functions of my application is to graph 5 different variables for a long period of time (currently about 80 minutes), and then save off all of the data to a .csv file with my app the way it is now as well as a .bmp image of the graph (maxed out canvas width with 380 pixel height).

    So TB has no problem with this - and I'm generating 1348921 x 380 pixel .bmp files just fine. It's so fantastic to be able to have a complete record of everything the user saw during the run.

    Thanks TB!

    *Brian

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,281
    Blog Entries
    2
    Rep Power
    10
    eheh ...
    maybe one day you will let us know about how look your applications
    We are very curios.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,281
    Blog Entries
    2
    Rep Power
    10
    Quote Originally Posted by EmbeddedMan View Post
    What are the limits to arrays? Can I, for example, have a long array that has 1073741823 elements (2GB in size)? Or do all variables in a TB program together need to fit into 2GB?
    Limit is per process.
    You have to consider that thinBasic Core engine has its memory needs plus every module has its memory needs.
    Sum all together and subtract from 2GB: the rest is what remains to your script.

    I think you have to consider also security: imagine you have all data in memory and you application crash (whatever application not only thinBasic).
    What about your data? You have lost all.

    Better strategy would be to store data into some persistent support (files or local DB or remote DB) as first step, than read back data to show it.
    One application can get data and store, another application can read back data and show.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,281
    Blog Entries
    2
    Rep Power
    10
    Regarding drawing data into a Canvass, it is better to draw it inside a Timer event and not during %WM_INITDIALOG event.
    Otherwise you will not get any window until your drawing is finished and your app will quite sure hangs.

    So during %WM_INITDIALOG event just setup your window and controls and create a timer.
    Then draw during timer events.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  9. #9
    Quote Originally Posted by ErosOlmi View Post
    Limit is per process.
    You have to consider that thinBasic Core engine has its memory needs plus every module has its memory needs.
    Sum all together and subtract from 2GB: the rest is what remains to your script.

    I think you have to consider also security: imagine you have all data in memory and you application crash (whatever application not only thinBasic).
    What about your data? You have lost all.

    Better strategy would be to store data into some persistent support (files or local DB or remote DB) as first step, than read back data to show it.
    One application can get data and store, another application can read back data and show.

    Yes, ideally, that is the case. That requires more complex internal operation. One of the requirements of this program is that the entire graph (all 24 hrs of it, if possible) be 'scrollable' at all times. So the user should be able to scroll back to any point in the graph, zoom in and out, all while new data is coming in. I.e. "live".

    As it is right now, I'm also saving every new bit of data off into the .csv log file, which (after the fact) can be loaded into the program (canvas) and scrolled around to see what happened during the run. This actually works extremely well. So I'm not worried about data that's in RAM getting lost during a crash.

    It's very good to know about the 2GB total limit - TB has no way to allocate or use memory outside of this limit, correct? That's just fine - I will need to be clever with how I store and display things if I want to run for longer periods.

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,281
    Blog Entries
    2
    Rep Power
    10
    Quote Originally Posted by EmbeddedMan View Post
    TB has no way to allocate or use memory outside of this limit, correct?
    Correct.

    Only way is to develop a thinBasic 64bit but actually is impossible because the compiler I use for development, PowerBasic, is only 32bit and there are no plan to release a 64bit version.
    I'm considering to abandon PowerBasic for something else but will be a looooong way
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Canvas Fun
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 1
    Last Post: 18-11-2013, 16:04
  2. ListView control -> columns fixed width???
    By Oscar Ugolini in forum thinBasic General
    Replies: 5
    Last Post: 15-06-2012, 08:23
  3. Replies: 6
    Last Post: 16-06-2010, 06:40
  4. canvas example :)
    By lydia_sp in forum UI (User Interface)
    Replies: 1
    Last Post: 16-09-2009, 17:19
  5. DIALOG maximum size
    By martin in forum thinBasic General
    Replies: 5
    Last Post: 25-05-2009, 12:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •