Loading ...
Sorry, an error occurred while loading the content.

RE: [libertybasic] Delsegment and Flush

Expand Messages
  • Stefan Pendl
    ... Usually you delete the last segment before drawing additional objects, which are flushed at the end. In pseudo code: 1) delete segment 2) draw objects 3)
    Message 1 of 8 , Feb 5, 2011
    • 0 Attachment
      >
      > Jack asks Rod:
      >
      > In your code that follows, you have used these lines:
      > ...
      > > #1.gb "delsegment seg"
      > > #1.gb "flush seg"
      > ...
      > In this particular case, is the first line doing anything
      > that the second line does not do if used alone?
      > '----------------------------------------------------------------
      > From me, Mike:
      >
      > I read the Help files again.
      >
      > 'Flush' means 'push'ing the segment aside, after sticking it.
      > 'Delsegment' means just that; delete the segment.
      >
      > When I push a segment aside, it's still there; so I can still
      > 'redraw' it if needed. If there's no such need, I have to
      > delsegment it, or else more and more RAM will be used up.
      >
      > So, the short answer is, 'flush' will not 'del'.
      >
      > What I want to ask is, as Rod has used above, if you have
      > 'deleted' a segment, what is there remaining to be 'flushed'?
      >

      Usually you delete the last segment before drawing additional objects, which are flushed at the end.

      In pseudo code:

      1) delete segment
      2) draw objects
      3) flush segment
      4) restart by 1)

      FLUSH only makes sure to have your drawn objects visible after a window was minimized and restored or it has been covered by another
      window.

      One other use case is a graph plotter, where the grid does not change, but only the graph.

      1) draw grid
      2) flush grid
      3) redraw grid
      4) draw graph
      5) restart at 3)

      As you can see there are many concepts for managing memory usage during drawing.


      ---
      Stefan Pendl
      http://stefanpendl.runbasichosting.com/

      Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
      Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

      Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

      Books at http://www.lulu.com/ and http://www.amazon.com/
      Alyce Watson ... APIs for Liberty BASIC
      Carl Gundel .... Beginning Programming with Liberty BASIC

      Windows 7 Home Premium 64-bit RTM
      AMD Turion X2 RM-70 2GHz, 4GB RAM
    • Rod
      Sorry, should have explained this with rem statements. Stefan has made a start. I find FLUSH a pain in the butt to get my head round. The code I use: #1.gb
      Message 2 of 8 , Feb 5, 2011
      • 0 Attachment
        Sorry, should have explained this with rem statements. Stefan has made a start. I find FLUSH a pain in the butt to get my head round. The code I use:

        #1.gb "delsegment seg"
        #1.gb "flush seg"

        Is bullet proof and self managing.

        You can tie yourself in knots thinking through FLUSH and DELSEGMENT, I don't anymore I just use the above code.

        The immediate and puzzling bit is why delete first, when surely there is no segment flushed yet? Well the answer is that Liberty does not care that there is no segment to delete so first time through it does nothing. From then on though it becomes automatic and self managing.

        first time through
        the first delete does nothing, seg will be 0
        flush saves the segment and ups seg to 1

        second time through
        we delete seg 1 it's going to be replaced right now
        flush saves the new segment and ups seg to 2

        third time through
        we delete seg 2
        flush saves the new segment and ups seg to 3

        and so on, memory use is contained to one flushed segment, the most recent one.
      • Sam
        I think the confusion arises because the term flush is a misnomer. It suggests get rid of . It might better be called store . It takes the temporary list
        Message 3 of 8 , Feb 5, 2011
        • 0 Attachment
          I think the confusion arises because the term "flush" is a misnomer. It suggests "get rid of". It might better be called "store". It takes the temporary list of most recent draw commands, stores it as a "segment" and makes that segment part of a more permanent list, which is accessed when the window refreshes itself--as when you cover and then uncover the window. That is why "flush" causes the graphics to "stick". The temporary list gets cleared, so "flush" is accurate in that sense, but the contents are not thrown away, which is why "flush" is misleading and causes confusion.

          The list of commands gets stored as a "segment", which you assign a name if you want to refer to it later. One reason to refer to it is to delete it when it is no longer meaningful. But in some applications you will periodically redraw everything from scratch, starting with the "cls" command to clear all contents, which also deletes all existing segments. In that case you don't have to name segments and expressly delete them.

          It is handy that "delsegment seg" does not crash when you have not yet created the segment seg. Otherwise you would have to create a "first time through" flag so you would skip delsegment the first time.

          Sam W.

          --- In libertybasic@yahoogroups.com, "Rod" <rodbird@...> wrote:
          >
          > Sorry, should have explained this with rem statements. Stefan has made a start. I find FLUSH a pain in the butt to get my head round. The code I use:
          >
          > #1.gb "delsegment seg"
          > #1.gb "flush seg"
          >
          > Is bullet proof and self managing.
          >
          > You can tie yourself in knots thinking through FLUSH and DELSEGMENT, I don't anymore I just use the above code.
          >
          > The immediate and puzzling bit is why delete first, when surely there is no segment flushed yet? Well the answer is that Liberty does not care that there is no segment to delete so first time through it does nothing. From then on though it becomes automatic and self managing.
          >
          > first time through
          > the first delete does nothing, seg will be 0
          > flush saves the segment and ups seg to 1
          >
          > second time through
          > we delete seg 1 it's going to be replaced right now
          > flush saves the new segment and ups seg to 2
          >
          > third time through
          > we delete seg 2
          > flush saves the new segment and ups seg to 3
          >
          > and so on, memory use is contained to one flushed segment, the most recent one.
          >
        • paradisejb
          ... Thank you very much, Rod (and to others). That was an explanation even I can understand! I ll try to retain your advice as SOP. In this case, however,
          Message 4 of 8 , Feb 5, 2011
          • 0 Attachment
            --- In libertybasic@yahoogroups.com, "Rod" <rodbird@...> wrote:
            >
            > Sorry, should have explained this with rem statements. Stefan has made a start. I find FLUSH a pain in the butt to get my head round. The code I use:
            >
            > #1.gb "delsegment seg"
            > #1.gb "flush seg"
            >
            > Is bullet proof and self managing.
            >
            > You can tie yourself in knots thinking through FLUSH and DELSEGMENT, I don't anymore I just use the above code.
            > ...snip

            Thank you very much, Rod (and to others). That was an explanation even I can understand! I'll try to retain your advice as SOP.

            In this case, however, since the graphics are drawn only once, I'm 'guessing' that the delsegment is not needed - albeit, not of any harm.

            If the user could click from month to month, I can see the benefit, and importance of, the delsegment.

            My analogy is that once the graphics are FLUSHED, they are "committed to memory", and are there to be reused whenever the window "needs" to be redrawn, as in the case of restoring after a minimize action. That memory will stay, unaltered, as long as no additional graphics are drawn by the program, or the program is ended.
          • paradisejb
            Thanks, Sam. You have helped to reinforce the concept in my head.
            Message 5 of 8 , Feb 5, 2011
            • 0 Attachment
              Thanks, Sam. You have helped to reinforce the concept in my head.


              --- In libertybasic@yahoogroups.com, "Sam" <swetterlin@...> wrote:
              >
              > I think the confusion arises because the term "flush" is a misnomer. It suggests "get rid of". It might better be called "store". It takes the temporary list of most recent draw commands, stores it as a "segment" and makes that segment part of a more permanent list, which is accessed when the window refreshes itself--as when you cover and then uncover the window. That is why "flush" causes the graphics to "stick". The temporary list gets cleared, so "flush" is accurate in that sense, but the contents are not thrown away, which is why "flush" is misleading and causes confusion.
              >
              > The list of commands gets stored as a "segment", which you assign a name if you want to refer to it later. One reason to refer to it is to delete it when it is no longer meaningful. But in some applications you will periodically redraw everything from scratch, starting with the "cls" command to clear all contents, which also deletes all existing segments. In that case you don't have to name segments and expressly delete them.
              >
              > It is handy that "delsegment seg" does not crash when you have not yet created the segment seg. Otherwise you would have to create a "first time through" flag so you would skip delsegment the first time.
              >
              > Sam W.
            • Stefan Pendl
              ... Freeze might be another term, which would better reflect what is done. Generally one only needs to know the opposite action of a drawing command. Any of
              Message 6 of 8 , Feb 5, 2011
              • 0 Attachment
                > >
                > > I think the confusion arises because the term "flush" is a
                > misnomer. It suggests "get rid of". It might better be called
                > "store". It takes the temporary list of most recent draw
                > commands, stores it as a "segment" and makes that segment
                > part of a more permanent list, which is accessed when the
                > window refreshes itself--as when you cover and then uncover
                > the window. That is why "flush" causes the graphics to
                > "stick". The temporary list gets cleared, so "flush" is
                > accurate in that sense, but the contents are not thrown away,
                > which is why "flush" is misleading and causes confusion.
                > >

                Freeze might be another term, which would better reflect what is done.

                Generally one only needs to know the opposite action of a drawing command.

                Any of the shape creation commands creates a drawing object, the opposite is DISCARD, which removes the information from the content
                list.
                FLUSH creates a marker in the content list, which will stop DISCARD from going further.
                DELSEGMENT removes this marker.
                REDRAW will display everything from the content list starting at the last marker up to the first object in the list.
                CLS will clear the content list entirely including the display of the graphics control/window.

                GETBMP creates a copy of the current display, so one can display a certain state of the graphics contents until UNLOADBMP is used to
                get rid of the memory image.

                With BMPSAVE one can preserve the memory image over reboots of the system by saving it to disk.
                KILL can free the disk from the saved image.

                As you can see, there are always at least two commands doing the opposite thing, one to create and one to remove an object in memory
                or on disk.


                ---
                Stefan Pendl
                http://stefanpendl.runbasichosting.com/

                Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
                Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

                Books at http://www.lulu.com/ and http://www.amazon.com/
                Alyce Watson ... APIs for Liberty BASIC
                Carl Gundel .... Beginning Programming with Liberty BASIC

                Windows 7 Home Premium 64-bit RTM
                AMD Turion X2 RM-70 2GHz, 4GB RAM
              • stefanhes
                I never read such a brite explanation. I have printed it out and will hang it beside my computer. Pershaps this can be added to the help file? Thank you Stefan
                Message 7 of 8 , Feb 11, 2011
                • 0 Attachment
                  I never read such a brite explanation. I have printed it out and will hang it beside my computer.

                  Pershaps this can be added to the help file?

                  Thank you Stefan Pendl



                  Stefan Hesseling

                  --- In libertybasic@yahoogroups.com, "Stefan Pendl" <>
                  > Freeze might be another term, which would better reflect what is done.
                  >
                  > Generally one only needs to know the opposite action of a drawing command.
                  >
                  > Any of the shape creation commands creates a drawing object, the opposite is DISCARD, which removes the information from the content
                  > list.
                  > FLUSH creates a marker in the content list, which will stop DISCARD from going further.
                  > DELSEGMENT removes this marker.
                  > REDRAW will display everything from the content list starting at the last marker up to the first object in the list.
                  > CLS will clear the content list entirely including the display of the graphics control/window.
                  >
                  > GETBMP creates a copy of the current display, so one can display a certain state of the graphics contents until UNLOADBMP is used to
                  > get rid of the memory image.
                  >
                  > With BMPSAVE one can preserve the memory image over reboots of the system by saving it to disk.
                  > KILL can free the disk from the saved image.
                  >
                  > As you can see, there are always at least two commands doing the opposite thing, one to create and one to remove an object in memory
                  > or on disk.
                  >
                  >
                  >
                • Gary Purkiss
                  i 100% agree with you i think them few commands can be a bit confusing and he made a good explanation of them....  ... From: stefanhes
                  Message 8 of 8 , Feb 12, 2011
                  • 0 Attachment
                    i 100% agree with you i think them few commands can be a bit confusing and he made a good explanation of them.... 

                    --- On Fri, 11/2/11, stefanhes <sjmhesseling@...> wrote:

                    From: stefanhes <sjmhesseling@...>
                    Subject: [libertybasic] Re: Delsegment and Flush
                    To: libertybasic@yahoogroups.com
                    Date: Friday, 11 February, 2011, 9:04
















                     









                    I never read such a brite explanation. I have printed it out and will hang it beside my computer.



                    Pershaps this can be added to the help file?



                    Thank you Stefan Pendl



                    Stefan Hesseling



                    --- In libertybasic@yahoogroups.com, "Stefan Pendl" <>

                    > Freeze might be another term, which would better reflect what is done.

                    >

                    > Generally one only needs to know the opposite action of a drawing command.

                    >

                    > Any of the shape creation commands creates a drawing object, the opposite is DISCARD, which removes the information from the content

                    > list.

                    > FLUSH creates a marker in the content list, which will stop DISCARD from going further.

                    > DELSEGMENT removes this marker.

                    > REDRAW will display everything from the content list starting at the last marker up to the first object in the list.

                    > CLS will clear the content list entirely including the display of the graphics control/window.

                    >

                    > GETBMP creates a copy of the current display, so one can display a certain state of the graphics contents until UNLOADBMP is used to

                    > get rid of the memory image.

                    >

                    > With BMPSAVE one can preserve the memory image over reboots of the system by saving it to disk.

                    > KILL can free the disk from the saved image.

                    >

                    > As you can see, there are always at least two commands doing the opposite thing, one to create and one to remove an object in memory

                    > or on disk.

                    >

                    >

                    >






























                    [Non-text portions of this message have been removed]
                  Your message has been successfully submitted and would be delivered to recipients shortly.