|
t4urean wrote: But If i minimize the application. The memory used drops down from 44k to a 7-8k and if i maximize it it starts increasing again. I believe that it is a Garbage collection problem.
No it is not. What you are seeing is not the memory your application is using but the memory it has "reserved" for use. That will generally rise as the application is used. When it is minimised the reservation is removed and you see a value closer to the actual amount used.
There is nothing wrong with this and your application is most likely functioning properly. If you want to see the actual amount of memory used by your application then you should look at the performance counters for the process. You can access these through Administrative Tools --> Performance.
|
|
|
|
|
Do you think an article about how to and how not to measure managed memory (and why) would be useful? I've seen this question asked so many times.
|
|
|
|
|
S. Senthil Kumar wrote: Do you think an article about how to and how not to measure managed memory (and why) would be useful?
Yes.
|
|
|
|
|
S. Senthil Kumar wrote: o you think an article about how to and how not to measure managed memory (and why) would be useful?
Tnere isn't one already?
---
Year happy = new Year(2007);
|
|
|
|
|
|
Don't look at the Memory tab in Task Manager. Instead, look at the Virtual Memory tab, which will give you a better idea of your apps actual working set.
|
|
|
|
|
As a footnote to what the others have posted, they've all said that Task Manager show you how much memory your application has been allocated. You might be wondering why that number stays so high if you free up the memory in your app.
Well, your application doesn't get it's memory from Windows. It gets memory from the .NET Common Lanugage Runtime, or if your familiar with Java, that refers to a virtual machine. The virtual machine (.NET CLR) aquires blocks of memory from Windows and it's put into a pool called the Managed Heap, actually a couple of different pools, but for simplicity... Your application allocates objects by requesting blocks of memory from the Managed Heap. When these objects aren't needed any more, the memory is freed back to the Managed Heap, not Windows. If the CLR detects that it's not going to need as much memory as it has reserved, it shrinks the Managed Heap and returns that memory back to Windows.
I hope that makes it a little easier to understand.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Hi
I got a problem with the project i'm building, i'm using StreamWriter and to append text to a textfile, so the text file look like this:
entry1
entry2
entry3
*blank row*
entry4
entry5
entry6
*blank row*
i do that with this code:
StreamWriter sw = File.AppendText("test.txt");<br />
sw.WriteLine(tb1.Text);<br />
sw.WriteLine(tb2.Text + " : " + tb21.Text);<br />
sw.WriteLine(tb3.Text);<br />
sw.WriteLine();<br />
sw.Flush();<br />
sw.Close();
Then i use a loop and array to read those files into my application.
TextReader TR = new StreamReader("test.txt");<br />
int NumberOfLines = 20;<br />
string[] ListLines = new string[NumberOfLines];<br />
for (int i = 1; i < NumberOfLines; i++)<br />
{<br />
ListLines[i] = TR.ReadLine();<br />
}
Now i got the problem, i need to be able to delete/change the "packs" between the blank line, was thinking something like making a backup of the file and re-writing it, without the selected pack (using a listbox to select) or in some way replace that pack with what the user types in instead when i hit the delete or change button. The problem is i dont know how to get the "new" text to the same position as the old when i change it. Anyone got an idea?
Sorry if i confuse you
--
Light is faster than sound... Thats why some people look smart till they start to talk.
|
|
|
|
|
How about:
TextReader tr = new StreamReader("test.txt");
int numberOfLines = 20;
string[] listLines = new string[NumberOfLines];
int i=0;
while(i < numberOfLines)
{
string line = tr.ReadLine();
if (line == null)
break;
if (line == string.Empty)
continue;
listLines[i] = line;
i++;
}
|
|
|
|
|
Is there any reason why you have to work with text files? If not I would do something like this:
(There's a bug in the pre tag... it doesn't like generics in examples!)
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
[Serializable()]
[XmlRootAttribute("Pack")]
public class Pack
{
private List<string> items;
public Pack()
{
items = new List<string>();
}
public List<string> Items
{
get { return items; }
set { items = value; }
}
public void Load(string filename)
{
XmlSerializer serialiser = new XmlSerializer(typeof(Pack));
Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read);
this.Items = ((Pack)serialiser.Deserialize(stream)).Items;
stream.Close();
}
public void Save(string filename)
{
XmlSerializer serialiser = new XmlSerializer(typeof(Pack));
Stream stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
serialiser.Serialize(stream, this);
stream.Close();
}
}
|
|
|
|
|
bobsugar222 wrote: (There's a bug in the pre tag... it doesn't like generics in examples!)
That's because it doesn't html encode the text, so the browser thinks that it is a broken html tag and ignores it.
You can use < and > to display the < and > characters.
---
Year happy = new Year(2007);
|
|
|
|
|
Sorted. Cheers
|
|
|
|
|
Thank you for your answers. The reason i work with text files is that this is my first "real" c# project, and i'm not very skilled in using it. Was mainly playing around trying to find a way to solve my problems. Found a number of problems with it though so thinking of using access database instead.
If you could add some comments to the above code example i'd be grateful, dont really understand every part of it.
Thanks
--
Light is faster than sound... Thats why some people look smart till they start to talk.
|
|
|
|
|
does someone know how to add sheet into a workbook
if i am writing in C#?
|
|
|
|
|
You'll want to look into the Office PIAs[^] to do that. The documentation that comes with it should help.
|
|
|
|
|
This is my first time into generating an XML file via a C# windows form.
Here are the specifics:
1) I need to use an existing datatable with rows and columns and export these to an XML file (I know I can use WriteXML), however there is a schema file that is to be used to generate the XML exported file.
Any help is greatly appreciated, as I've searched the web for such a solution, but have come up empty.
Thanks !
|
|
|
|
|
Unfortunately, The DataTable.WriteXml method uses the schema of the current DataTable object.
I would probably approach this by creating my own serializable class that you can feed the DataTable in to the constructor as a parameter. Depending on how OO I want to be I may add an XmlSchema object as an overload. You'd then have to do all the parsing of the DataTable to your schema manually.
|
|
|
|
|
Any snippet code that you can provide ?
|
|
|
|
|
if you have a fixed (read typed) DataTable schema and a fixed XML schema then it would be a matter of parsing your dataTable into an xmlDocument with your xmlSchema. Something like this:
public static void WriteMyDataTableToXml(MyTypedDataTable dataTable, string filename)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Save(filename);
}
If the table and schema are variable in structure then that's a little more complicated.
|
|
|
|
|
If you're using .NET 2.0, I'd just add to that:
xmlDocument.Schemas.Add("",schemaFilename);
//load xmlDocument here
xmlDocument.Validate(validationHandler);
//save the document
|
|
|
|
|
I wonder if this logic would work:
1) Write datatable out to an XML file without a schema
2) Read back in the XML file and validate it against the known schema and if it passes leave the XML file, else delete the XML file and give the user a message that the schema does not match the data in the datatable.
|
|
|
|
|
Why not do this in memory? i.e. Why save the possibly invalid file to begin with?
|
|
|
|
|
I'm not sure how to do it in memory.
Also, if it does turn out to be valid, I need to create the XML file.
|
|
|
|
|
In memory just means writing the XML to a string variable. How you do it depends on your current method of generating the XML and saving it to a file.
//e.g. with XmlTextWriter
XmlTextWriter xmlTextWriter = new XmlTextWriter(fileName, encoding);
//saves to a file.
StringBuilder sb = new StringBuilder()
XmlTextWriter xmlTextWriter = new XmlTextWriter(new StringWriter(sb));
//allows you to save to a string.
string myString = sb.ToString();
//Use:
xmlDocument.LoadXml(myString);
//before validating and saving the XmlDocument
Good Luck!
|
|
|
|