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

What happens when you run low on RAM?

Expand Messages
  • carlg@libertybasic.com
    Someone today asked me via email today how Windows deals with virtual memory when running Liberty BASIC. Here was my answer. ... Hi! Are you getting an error
    Message 1 of 2 , Apr 7, 2001
    • 0 Attachment
      Someone today asked me via email today how Windows deals with virtual
      memory when running Liberty BASIC. Here was my answer.

      -------------

      Hi!

      Are you getting an error from Windows, or is your machine grinding to
      a crawl? Windows will certainly try to allocate enough memory as the
      program runs. Usually this shouldn't be a problem. Here are some
      short examples that run fine on my P166 32MB laptop.

      'this runs easily, of course
      dim a$(20000)
      end

      Now let's stick some data in the array.

      'allocate 20,000*24 string bytes = 480,000
      dim a$(20000)
      start = time$("ms")
      for x = 1 to 20000
      a$(x) = Version$+DefaultDir$+BackgroundColor$
      next x
      print "time to run = "; (time$("ms")-start) / 1000; " seconds"
      end
      time to run = 5.22 seconds

      Then I increased this four-fold to allocate almost 2 million bytes.

      'allocate 80,000*24 string bytes = 1,920,000
      dim a$(80000)
      start = time$("ms")
      for x = 1 to 80000
      a$(x) = Version$+DefaultDir$+BackgroundColor$
      next x
      print "time to run = "; (time$("ms")-start) / 1000; " seconds"
      end

      time to run = 26.75 seconds

      When I increased to 400000 (or 10 megabytes), it ran but took 6
      minutes as shown:

      time to run = 306.49 seconds

      Once you begin to exceed the free RAM things get very slow. Windows
      will indeed allocate virtual memory, but every time the automatic
      garbage collector kicks in your hard drive will thrash like crazy
      because it is examining all the application memory space, swapping
      things in and out of virtual memory just to get a look at each piece.
      This is a bit like running the disk defragmentor over and over (have
      you ever sat and watched for hours while your hard disk got
      defragmented?).

      On my 32MB laptop it seems like once I try to allocate more than 15
      or so megabytes for strings, then it starts to thrash. A little more
      than that, and it becomes extremely sluggish to switch between
      applicatons or do anything else.

      Trying this on the current 32-bit LB v3 work, I get the 400000 array
      example to run in 56 seconds, an improvement of more than 5x!!!
      However, once I try to exceed my available RAM, it runs into hard
      drive thrashing problems almost as bad as the 16-bit LB.

      So the lesson is, RAM is golden. Get as much of it as you can!

      -Carl
    • Kenneth J. Lewis, Sr.
      Another point to consider is that if you let windoze manage your virtual memory, it is constantly checking and changing the swapfile size. This slows things
      Message 2 of 2 , Apr 7, 2001
      • 0 Attachment
        Another point to consider is that if you let windoze manage your virtual
        memory, it is constantly checking and changing the swapfile size. This slows
        things down even more. I have my virtual memory set to a minimum of 200 MB
        and a maximum of 200 MB. If your minimum and maximum are the same windows
        doesn't mess with it, If they are different then windows will be constantly
        checking and resizing it.

        Ken


        ----- Original Message -----
        From: <carlg@...>
        To: <libertybasic@yahoogroups.com>
        Sent: Saturday, April 07, 2001 1:56 PM
        Subject: [libertybasic] What happens when you run low on RAM?


        > Someone today asked me via email today how Windows deals with virtual
        > memory when running Liberty BASIC. Here was my answer.
        >
        > -------------
        >
        > Hi!
        >
        > Are you getting an error from Windows, or is your machine grinding to
        > a crawl? Windows will certainly try to allocate enough memory as the
        > program runs. Usually this shouldn't be a problem. Here are some
        > short examples that run fine on my P166 32MB laptop.
        >
        > 'this runs easily, of course
        > dim a$(20000)
        > end
        >
        > Now let's stick some data in the array.
        >
        > 'allocate 20,000*24 string bytes = 480,000
        > dim a$(20000)
        > start = time$("ms")
        > for x = 1 to 20000
        > a$(x) = Version$+DefaultDir$+BackgroundColor$
        > next x
        > print "time to run = "; (time$("ms")-start) / 1000; " seconds"
        > end
        > time to run = 5.22 seconds
        >
        > Then I increased this four-fold to allocate almost 2 million bytes.
        >
        > 'allocate 80,000*24 string bytes = 1,920,000
        > dim a$(80000)
        > start = time$("ms")
        > for x = 1 to 80000
        > a$(x) = Version$+DefaultDir$+BackgroundColor$
        > next x
        > print "time to run = "; (time$("ms")-start) / 1000; " seconds"
        > end
        >
        > time to run = 26.75 seconds
        >
        > When I increased to 400000 (or 10 megabytes), it ran but took 6
        > minutes as shown:
        >
        > time to run = 306.49 seconds
        >
        > Once you begin to exceed the free RAM things get very slow. Windows
        > will indeed allocate virtual memory, but every time the automatic
        > garbage collector kicks in your hard drive will thrash like crazy
        > because it is examining all the application memory space, swapping
        > things in and out of virtual memory just to get a look at each piece.
        > This is a bit like running the disk defragmentor over and over (have
        > you ever sat and watched for hours while your hard disk got
        > defragmented?).
        >
        > On my 32MB laptop it seems like once I try to allocate more than 15
        > or so megabytes for strings, then it starts to thrash. A little more
        > than that, and it becomes extremely sluggish to switch between
        > applicatons or do anything else.
        >
        > Trying this on the current 32-bit LB v3 work, I get the 400000 array
        > example to run in 56 seconds, an improvement of more than 5x!!!
        > However, once I try to exceed my available RAM, it runs into hard
        > drive thrashing problems almost as bad as the 16-bit LB.
        >
        > So the lesson is, RAM is golden. Get as much of it as you can!
        >
        > -Carl
        >
        >
        >
        >
        > To unsubscribe from this group, send an email to:
        > libertybasic-unsubscribe@egroups.com
        >
        >
        >
        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.