Board index » delphi » TMemoryStream max size?

TMemoryStream max size?

Hi,

I need to read large files (20 - 50 MB) and store them temporarily in
MemoryStream for fast processing.
It seems to work fine on my machine (128 MB RAM), but I'm not sure what
would happen on a computer with less memory.
Is the maximum allowed size of TMemoryStream limited by size of physical
memory or is it smart enough to use windows swap file if running low on
resources?

TIA
Eric

 

Re:TMemoryStream max size?


Quote
In article <3b031...@kastagir.senet.com.au>, "es" <er...@senet.com.au> writes:
>It seems to work fine on my machine (128 MB RAM), but I'm not sure what
>would happen on a computer with less memory.
>Is the maximum allowed size of TMemoryStream limited by size of physical
>memory or is it smart enough to use windows swap file if running low on
>resources?

Within the sizes you are talking about, there is no limit on a TMemoryStream.
As with most programs, TMemoryStream uses whatever it needs, if there's not
enough RAM available at the time (taking into account all other programs,
processes and OS in use) then window swaps memory out to disk. If there is not
enough hard disk for what is required with a swap file (or the swap file is
limited by a user specification), then an out of memory message is displayed
and the system {*word*88}s.

Use of the swap file is not under the control of applications but of the
operating system ie Windows.

Alan Lloyd
alangll...@aol.com

Re:TMemoryStream max size?


Quote
AlanGLLoyd <alangll...@aol.com> wrote in message

news:20010517104044.02037.00000459@nso-ms.aol.com...

Quote
> In article <3b031...@kastagir.senet.com.au>, "es" <er...@senet.com.au>
writes:

> >It seems to work fine on my machine (128 MB RAM), but I'm not sure what
> >would happen on a computer with less memory.
> >Is the maximum allowed size of TMemoryStream limited by size of physical
> >memory or is it smart enough to use windows swap file if running low on
> >resources?

> Within the sizes you are talking about, there is no limit on a
TMemoryStream.
> As with most programs, TMemoryStream uses whatever it needs, if there's
not
> enough RAM available at the time (taking into account all other programs,
> processes and OS in use) then window swaps memory out to disk. If there is
not
> enough hard disk for what is required with a swap file (or the swap file
is
> limited by a user specification), then an out of memory message is
displayed
> and the system {*word*88}s.

> Use of the swap file is not under the control of applications but of the
> operating system ie Windows.

> Alan Lloyd
> alangll...@aol.com

Alan ,

Thanks for that, sounds reassuring.
However, out of curiosity I tried to do the same thing using TFileStream.
It didn't work out too well - after loading fairly large (40 MB) file using
LoadFromFile()
the computer spits out a message about being out of memory and that's it.
Am I to take it that FileStream is dumber than MemoryStream?
Sorry to bother you again, but this stuff is fairly new to me (coming from
VB world) .

Regards
Eric

Re:TMemoryStream max size?


The message <3b046...@kastagir.senet.com.au>
  from  "es" <er...@senet.com.au> contains these words:

Quote
> AlanGLLoyd <alangll...@aol.com> wrote in message
> news:20010517104044.02037.00000459@nso-ms.aol.com...
> > In article <3b031...@kastagir.senet.com.au>, "es" <er...@senet.com.au>
> writes:

> > >It seems to work fine on my machine (128 MB RAM), but I'm not sure what
> > >would happen on a computer with less memory.
> > >Is the maximum allowed size of TMemoryStream limited by size of physical
> > >memory or is it smart enough to use windows swap file if running low on
> > >resources?

> > Within the sizes you are talking about, there is no limit on a
> TMemoryStream.
> > As with most programs, TMemoryStream uses whatever it needs, if there's
> not
> > enough RAM available at the time (taking into account all other programs,
> > processes and OS in use) then window swaps memory out to disk. If there is
> not
> > enough hard disk for what is required with a swap file (or the swap file
> is
> > limited by a user specification), then an out of memory message is
> displayed
> > and the system {*word*88}s.

> > Use of the swap file is not under the control of applications but of the
> > operating system ie Windows.

> > Alan Lloyd
> > alangll...@aol.com
> Alan ,
> Thanks for that, sounds reassuring.
> However, out of curiosity I tried to do the same thing using TFileStream.
> It didn't work out too well - after loading fairly large (40 MB) file using
> LoadFromFile()
> the computer spits out a message about being out of memory and that's it.
> Am I to take it that FileStream is dumber than MemoryStream?
> Sorry to bother you again, but this stuff is fairly new to me (coming from
> VB world) .
> Regards
> Eric

With TFileStream you have nominated a disk file. The swapfile is
also a disk file. If there is not enough disk space to hold the
data for the nominated file what should Windows do with it? Even
if the swap file is on another drive, the data still will not fit
in the file you have nominated.

One reason you may not be able to fit the data in TfileStream
is because you have previously used TmemoryStream. The Windows
swapfile has a habit of growing and growing but I have never
seen it shrink. this can be a problem if the swap file and the
file you are trying to save to are on the same drive.

Check the size of your swap file (.swp). If you don't
like what you see, come out of Windows, go to DOS and
delete it. When you start Windows it will make a new one
from scratch.

The logic behind not deleting it automatically used to be
that that swapping is slower if windows has to grow the
swap file. I have not noticed any difference on my machine
after deleting it to what it was before, but then again
hard drives are much quicker nowadays than they used to be.

--
Sincerely,

Andreas Kyriacou
----------------
http://www.andrikkos.co.uk (Imagine! Image Viewer)

Other Threads