Announcement

Collapse
No announcement yet.

Virtual Graphic - Memory Demand?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Virtual Graphic - Memory Demand?

    I assumed that using Graphic Set Virtual 8000,4000 would create a hidden bitmap of about 32MB - increasing the memory footprint of the app.

    But in this example, Task Manager shows no increase in memory requirements at all when going Virtual.

    Code:
    'Compilable Example:
    #Compile Exe
    #Dim All
    %Unicode = 1
    #Include "Win32API.inc"
    
    Enum Equates Singular
       IDC_ButtonA  = 500
       IDC_ButtonB
       IDC_Graphic
    End Enum
    
    Global hDlg As Dword
    
    Function PBMain() As Long
       Dialog New Pixels, 0, "Fixed",300,300,300,200, %WS_OverlappedWindow To hDlg
       Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,300,200
       Graphic Attach hDlg, %IDC_Graphic
       Control Add Button, hDlg, %IDC_ButtonA,"Virtual", 50,10,100,20
       Control Add Button, hDlg, %IDC_ButtonB,"Fixed", 50,50,100,20
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_Command
             Select Case Cb.Ctl
                Case %IDC_ButtonA : Graphic Set Virtual 8000,4000 : Dialog Set Text hDlg, "Virtual"
                Case %IDC_ButtonB : Graphic Set Fixed : Dialog Set Text hDlg, "Fixed"
             End Select
       End Select
    End Function
    But, if I add a small BMP to the Graphic Virtual control, the app does seem to grow by the size of the BMP.

    Bob apparently does something more than a very large bitmap ... not sure of the details.

  • #2
    Yeah, since we don't know, we can only guess that Graphic Set Virtual equals SetScrollInfo, nothing more. What we do know is that a Graphic control is a simple Static (Label) control.. and from there on it becomes a guessing game. A memDC "canvas" is probably created (CreateCompatibleDC + CreateCompatibleBitmap) at some point and BitBlt'd och StretchBlt'd under WM_CTLCOLORSTATIC.. or a subclassed Static control's WM_PAINT or WM_ERASE.

    Comment


    • #3
      But reading the manual after guessing a reply, I see it says "When executed, a new virtual bitmap of the specified height and width is created." So, sorry - I got nothing..

      Comment


      • #4
        The graphic is stored by the system, not by your program.
        The memory use DOES increase if you look at overall memory rather than just the memory used by your program.
        Make the virtual graphic bigger 20000x20000 and it becomes more obvious.

        Click image for larger version  Name:	VirtualVsFixed.png Views:	2 Size:	39.3 KB ID:	806572

        Comment


        • #5
          Hi , this is pretty interesting
          Can someone provide a working usage of this Virtual graphics technique ?
          maybe draw a virtual bitmap and display it later?

          Comment


          • #6
            Howdy, Dave!

            "... stored by the system."
            Nice sleuthing! But, how can that be? I wasn't aware that memory requested my app has the option of being in-process memory or not? Can I do that intentionally ... ask for memory that doesn't increase my app's footprint?

            Comment


            • #7
              Looks like it may be using a memory mapped file based on what Procexp shows

              You can do the same yourself in any application by creating a MMF.

              Comment


              • #8

                Gary,
                " But, how can that be?"
                It can be because the graphics processor handles the graphics for display, not the CPU.
                The graphics processor might have its own memory or it might share the system memory but it's outside of the memory your program can access.

                It's not an option that you can choose. It's just how graphics work.
                When you use something like GRAPHIC SET BITS, your accessible bitmap in your application's memory is copied to the device memory for display.
                That device memory is outside of your application's memory space. It's the display adapter which needs the memory, not your application.

                Here's what my laptop says about the memory for my display.
                It has access to 4059MB of system memory plus 128MB of dedicated graphics memory.

                Click image for larger version

Name:	GraphicAdapterMemory.png
Views:	62
Size:	29.2 KB
ID:	806584

                Comment


                • #9
                  Don't use Task Manager for this ... use code at appropriate points in your program. Be sure to put inside a ...
                  Code:
                  #IF %SHOW_MEMORY_USAGE
                         memory call
                  #ENDIF
                  . code block so you can quickly skip for production version of your code.

                  LINKS ===> :

                  Add Process Memory Usage Report to any program 1-12-04
                  Discussion, results: http://www.powerbasic.com/support/pb...ad.php?t=20645


                  Oops those are the old ref lets see if we can find the current ones..

                  Found 'Em.....

                  Here's the report code from the Source Code Forum (thank you, "Search")

                  https://forum.powerbasic.com/forum/u...to-any-program

                  Discussion and results
                  https://forum.powerbasic.com/forum/u...y-info?t=20645


                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    I just re-read that "discussion and results" thread which I started in 2004... a lot of the same kinds of issues from... oh, call it last week!

                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X