2 Questions - one about memory usuage and the other about files

  • Thread starter Thread starter Cowboy \(Gregory A. Beamer\) [MVP]
  • Start date Start date
C

Cowboy \(Gregory A. Beamer\) [MVP]

It really depends on what the program does. .NET handles memory differently
from previous Microsoft systems, ie COM. It is quite normal for an
executable to consume large quantities of memory, as the .NET system eats
memory until it needs to clean up, while COM has you explicitly destroy
objects. I would not panic on this one.

Do not have the oldest file code. Apologies.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
If a compiled exe project is under 400kb, why does it take up 15Mb when
running? Is this normal?

If not, how do I restrict the amount of memory it can consume?

Secondly, does anyone have a bit of code that will traverse a directory
structure and return the name of the oldest file?


Thanks in advance....

Dave.
 
basically, all it does is sit in the background, and every month or
predefined time, zips up and archives the previous months IIS log files.

as i said - 380kb (ish) as an exe, but using 15Mb+ when running! Everything
is disposed when needed, closed etc, garbage collected etc, etc. Can't think
what else I need!
 
basically, all it does is sit in the background, and every month or
predefined time, zips up and archives the previous months IIS log files.

as i said - 380kb (ish) as an exe, but using 15Mb+ when running!

What makes you think the size of an executable has anything significant
to do with the size a program should take in memory? You can write very
small programs which deal with large amounts of data, and other
programs may be smaller than their executable size (if they don't use
all the classes and methods within the executable).
Everything is disposed when needed, closed etc, garbage collected
etc, etc. Can't think what else I need!

You don't need anything. Just don't worry about it.
 
I have this class which will list the output of a dos command to a string array:

public class ProcessDataRetriever
{
public static string[] GetData(string cmd, string args)
{
using(Process p = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo(cmd, args);
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
p.StartInfo = psi;
p.Start();
ArrayList a = new ArrayList(); string s;
while((s = p.StandardOutput.ReadLine()) != null) a.Add(s);
p.Close();
return (string[])a.ToArray(typeof(string));
}
}
}

If you do the dos command "cmd.exe /c dir *.* /O:d" then it will list the files in date order. The oldest file will therefore be the first one in the array.
 
15 MB isn't really that big.
Look in task manager and you'll see at least a few processes taking up more than that.
 
This can be done, in fewer lines of code, with less memory usage, and
quicker, using .NET calls...

Why would anyone EVER shell out a process to find a file?

--- Nick


DirectoryInfo di = new
DirectoryInfo(@"c:\my\directory\name\goes\here");
FileSystemInfo[] allfiles= di.GetFileSystemInfos();
FileSystemInfo oldestfile = null;
foreach (FileSystemInfo fiNext in allfiles)
{
if ((fiNext.Attributes & FileAttributes.Directory) == 0)
// exclude directories
{
if (oldestfile == null)
oldestfile = fiNext;
else
if (fiNext.GetLastWriteTimeUtc <
oldestfile.GetLastWriteTimeUtc)
oldestfile = fiNext;
}
}
return fiNext.FullName;



Beeeeeeeeeeeeves said:
I have this class which will list the output of a dos command to a string array:

public class ProcessDataRetriever
{
public static string[] GetData(string cmd, string args)
{
using(Process p = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo(cmd, args);
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
p.StartInfo = psi;
p.Start();
ArrayList a = new ArrayList(); string s;
while((s = p.StandardOutput.ReadLine()) != null) a.Add(s);
p.Close();
return (string[])a.ToArray(typeof(string));
}
}
}

If you do the dos command "cmd.exe /c dir *.* /O:d" then it will list the
files in date order. The oldest file will therefore be the first one in the
array.
 
Back
Top