|
-
Jun 2nd, 2006, 10:34 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [02/03] Memory usage
I am creating a program that will log activity of my program (like file renaming and such). This program will be on for days straight, and my program will log all activity. As of now, I have it writing to a text box and then also writing to a log file like this:
VB Code:
txtActivity.Text = txtActivity.Text & "Monitoring Started on " & DateAndTime.Now & vbNewLine
txtActivity.Text = txtActivity.Text & "Logging Activity to: " & logFile & vbNewLine
writeToLogFile("Monitoring Started on " & DateAndTime.Now)
writeToLogFile("Logging Activity to: " & logFile)
Private Sub writeToLogFile(ByVal loggedText As String)
Dim oWrite As New StreamWriter(logFile)
oWrite.WriteLine(loggedText)
oWrite.Flush()
oWrite.Close()
End Sub
Over time, having the log write to a text box will use up a lot of memory right? Would it be more efficient to write to a log and read from the log file and output that data to a text box?
Last edited by SomethinCool; Jun 2nd, 2006 at 01:03 PM.
-
Jun 2nd, 2006, 12:43 PM
#2
Re: [02/03] Memory usage
If you write to the Trace class (e.g. using
VB Code:
Trace.WriteLine("My message...")
then you can attach different "trace listeners" to store that to a file, or the windows event log or any other log target...
-
Jun 2nd, 2006, 01:02 PM
#3
Thread Starter
Frenzied Member
Re: [02/03] Memory usage
I'm looking more for a text file log like an IIS server connection and request log. Will this let me do that? I've never used the trace class before.
-
Jun 2nd, 2006, 02:30 PM
#4
Re: [02/03] Memory usage
Some stats if you decide to stick with a textbox to show the whole log all the time in a textbox:
In an app of mine a richtextbox with 590 000 lines and a total of 6 350 759 characters takes approx. 90 MB of RAM. Reloading it doesn't seem to increase the memory usage. I have 768 MB and a P4 1.4, all runs smoothly.
Thought it might be informative.
-
Jun 2nd, 2006, 05:29 PM
#5
Re: [02/03] Memory usage
Where is the memory question? In your write sub, you create the streamwriter, write data, then close the writer. When the sub exits, the objects are marked for garbage collection and will be cleaned up once the garbage collector sweeps it up...
-
Jun 2nd, 2006, 07:19 PM
#6
Thread Starter
Frenzied Member
Re: [02/03] Memory usage
Where is the memory question? In your write sub, you create the streamwriter, write data, then close the writer. When the sub exits, the objects are marked for garbage collection and will be cleaned up once the garbage collector sweeps it up...
I know the StreamWriter is fine, but I'm writing to a textbox also which will write data for hours, maybe even days or months. If it gets too big it will crash the program. I was wondering what a more efficient way of display data would be.
-
Jun 2nd, 2006, 07:27 PM
#7
Frenzied Member
Re: [02/03] Memory usage
Why write to the textbox the entire time? Why not just load it into the textbox when you want to see it, and get rid of it when you are done looking at it?
-
Jun 2nd, 2006, 07:55 PM
#8
Thread Starter
Frenzied Member
Re: [02/03] Memory usage
I want it to show current activity of the program and what it is doing. I was thinking about possibly clearing out the data every hour and having it refresh, but I'm not sure if that is what I really want to do.
-
Jun 2nd, 2006, 09:54 PM
#9
Re: [02/03] Memory usage
I would suggest that you do a bit more work. Basically, there are two simple solutions. The first is what you have already suggested. The second would be to write it all to a file, and only display as needed. Since you don't want to do the second, and have concerns about the first, I would suggest a third approach that takes a bit more work.
There is no rational reason to show all of this in a textbox. It would be simply overwhelming after a fairly short amount of time. However, to meet your needs, you need to be displaying a large amount of it at any one time.
Another point I notice is that this seems to be episodic text data. Chunks of text will arrive sporadically, judging by your description. Therefore, a listbox might be your best solution, rather than a textbox. If you save it all to a class in the background that implements something like a stack or a list, you can keep the listbox refreshed from this class. You would need to set some maximum number of current items in the listbox, though this number could be REALLY big, but then you'd have the ability to scroll through it. You could adjust the properties of the listbox so that it appears much like a textbox, but you will have the advantage of being able to access any one item in the list, a feature which may have some utility to it.
In the background, the class would take care of saving everything to a text file, too. You could also arrange it so that it would reload after program re-start. Basically, though it takes a bit more work, having a class that collects the data would allow you to display it, save it, manage it, archive it, sort it, whatever. If you work with just a textbox, you get none of that. A bit more work, but MUCH more functionality can be designed in.
My usual boring signature: Nothing
 
-
Jun 5th, 2006, 07:17 AM
#10
Thread Starter
Frenzied Member
Re: [02/03] Memory usage
Well, if I wanted to clear a text box lets say every 30 seconds, how would I attempt to do this? Would I have to use a Timer?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|