|
My reply was to led mike.
You are on the right board AFAIK
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: How high does it climb? Infinitely?
Well I get bored before I have any conclusive data. No doubt there are far better methods to actually test like with a profiler etc.
So anyway this is mildly interesting I have a utility app that I use to work with XML files XPath statements etc. I initially wrote it years ago in VC++ it uses MSXML and hosts the browser for one of the views. So like a year ago or so I remade it using C#. Now the new version is slightly more feature rich from a UI perspective and you would therefore expect a larger memory footprint but all in all they are very similar.
So you start the old VC++ app and it loads in at around 14 meg. After opening a few files and manipulating the UI to view stuff etc it grows up around 18 meg and you can see it freeing memory and it settles down just over 17 megs.
The C# app loads at just over 26 megs and you can get it to climb from there. But if you minimize it it drops to 1.1 meg! Then when you restore it it jumps up to 12 meg and as you begin to work it (open files and run XPath queries, manipulate the views etc.), it climbs up to just over 18 meg and you can see it free memory back down to just under 18 megs.
So overall the C# app has slightly more bells and whistles and uses a slightly larger memory footprint once you minimize it and restore it. I have no idea what that is all about but I wouldn't expect significant memory consumption from a .NET Windows Forms app. The UI is definitely not as responsive as the native app but memory consumption I would have to say is very similar.
Oh yeah I am running XP Pro
|
|
|
|
|
I understand that some things will be held on to because they don't go out of scope. But it seems to me there are some serious problems within the .NET framework not properly releasing references. Consider the behavior of the Menu control:
Every time I click my "File" menu (just as an illustration), MORE memory is sucked up to generate the drop down (New, Open, Save, etc...). Sure, the Menu control never goes out of scope as long as the application is run, but why does it grab more memory every time? It seems to me that after the memory has been allocated once, that should be the end of it. If I call up the "File" menu a second time, there should be no reference left to the original fly-out. The memory consumption should stay constant because one reference was destroyed and one was created. But no. The framework sucks up the additional memory to create a new reference without reliquishing the old reference.
As many times as I expand any menu item, more memory is consumed. None is ever reliquished. And, as I stated in my original post, I took my unmanaged data out of the equasion. I'm talking about just running an application form with a menu system -- before I do any of the real application work or allocate any of the core data structure memory.
If .NET won't release any of the consumed Menu memory before application termination, then I might as well go back to VS6. That's just too sloppy.
|
|
|
|
|
AFAIK, the GC will kick-in whenever it feels like working or when a low memory situation. In my little world, I have never had a .NET application run out of memory that they gobbled up!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Like I mentioned to led mike, I don't use .NET GUI so I can't comment on the
specifics of your situation..
If I remember correctly from my tests, in an infinite loop allocating objects on the managed heap
and watching in the task manager, memory use would climb to around 300MB between each cleanup
by the GC. That was VS2003/.NET 1.1. Strangely, I cannot replicate that with VS2005 LOL
I'm trying to make an infinite loop that allocates and the memory never moves.
If you need to keep everything cleaned up immediately, Does GC.Collect() help?
If this stuff leaks why isn't everyone screaming about it? I would think by now
someone would have noticed. .NET would indeed be useless.
Cheers!
MArk
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Also, you can minimize memory usage in .NET by cutting back in the creation of mulitple or temporary small objects. For example, instead of doing a lot of string manipulations on a String , use a StringBuilder object instead.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I am aware of a few optimizations such as the use of StringBuilder. The behavior I noted is more apparent in items that are beyond my control -- such as the Menu control. Why should more memory be allocated every time a fly-out is invoked, yet when the fly-out disappears no memory is ever released?
However, I posted a similar thread on another board, and one of the respondants said that I'm looking at this all wrong. I have only Task Manager to gauge memory use, but he said I can't do that because a .NET application runs inside of a "virtual machine". Therefore Task Manager shows only what the VM is reserving, not necessarily what I'm using.
I only half-way buy this idea. Regardless whether .NET is running a VM or not, the fact is that every time I invoke a menu, or a dialog box, the Task Manager numbers go up. The respondant's point was that the number in TM will NOT go down because the VM has reserved that memory. Well fine. But if the memory is reserved, they why does it need to reserve even MORE memory the next time I trigger a fly-out menu? The memory was already reserved once. If the memory was truly freed after the fly-out disappeared the first time, the virt. mach. should not need to compound its memory reservation.
From that angle, it seems to me that Task Manager is indicating there is something wrong with .NET's virt. machine. BUT Mark has a very valid point that if there was truly something to be worried about, it seems like there would be a lot more people screaming about it.
The overwhelming opinion on this and other message boards is that I'm worried about nothing. I guess I don't know enough about .NET internals. All I know is that the numbers I saw in Task Mgr don't make a lot of sense, so I thought I'd inquire about it.
|
|
|
|
|
Your concern is quite natural and valid. I do not like to see wasted resources. However, I think the ultimate goal of the GC is efficiency over resource conservation. If the GC is constantly reclaiming and defragmenting memory, your application speed will suffer. You, as a programmer, gain freedom from resource management, but the trade off is this management is in a black box, and various opinions on what is going on in this black box.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I am trying to put information in an access database file (mdb) with an oledb connection. Everything seems fine but no new information is added to the database at the end.
This is the code I have now:
double Tabel_Panelinfo(String^ item_id, String^ use, String^ type)
{
int dblID = 10;
OleDbConnection^ myOleDbConnection = nullptr;
try
{
OleDbConnectionStringBuilder^ connectionBuilder = gcnew OleDbConnectionStringBuilder();
connectionBuilder->Provider = "Microsoft.Jet.OLEDB.4.0";
connectionBuilder->DataSource = "D:\\Data\\Visual Studio 2005\\Projects\\VertexBDXML-RandekSPL728\\VertexBDXML-RandekSPL728\\Tabel-XML.mdb";
myOleDbConnection = gcnew OleDbConnection(connectionBuilder->ToString());
myOleDbConnection->Open();
OleDbDataAdapter^ DataAdapter = gcnew OleDbDataAdapter("SELECT * FROM tblPanel", myOleDbConnection);
DataAdapter->FillError += gcnew FillErrorEventHandler(MyEventHandler::FillError);
DataAdapter->RowUpdated += gcnew OleDbRowUpdatedEventHandler(MyEventHandler::RowUpdated);
DataSet^ myDataSet = gcnew DataSet();
DataAdapter->MissingSchemaAction = MissingSchemaAction::Add;
DataAdapter->Fill(myDataSet, "tblPanel");
DataRow^ row = myDataSet->Tables["tblPanel"]->NewRow();
if (row != nullptr)
{
row["item_id"] = item_id;
row["use"] = use;
row["type"] = Convert::ToInt16(type);
DataAdapter->Update(myDataSet, "tblPanel");
}
}
catch(Exception^ e)
{
Console::WriteLine(e->Message);
}
finally
{
if ( myOleDbConnection != nullptr )
myOleDbConnection->Close();
}
return dblID;
}
Stefan
|
|
|
|
|
This is the managed C++ forum (as clearly stated on this page) and therefore the wrong forum for this question. Make sure you are using some sort of tutorial or example, there are many database articles here on code project (use the site navigation ). When you repost your question in the correct forum (Visual C++ / MFC ) be sure to reference the article or tutorial you are working from.
|
|
|
|
|
he's in the right forum, he's clearly using C++/CLI and not native C++.
|
|
|
|
|
ooops
apparently I have been brainwashed. I went off the subject.
|
|
|
|
|
|
I might be the only member stupid enough to pull that off!
Happy Friday... I'm out of here
|
|
|
|
|
See if adding the row to the table does it.
myDataSet->Tables["tblPanel"]->Rows->Add(row);
|
|
|
|
|
This still does not work, i added it in between the other code.
I now get exception for e { "Index was outside the bounds of the array."}
Is there maybe a good example to write information to an access database using C++.
I have found many examples but cannot find any that works in my project.
DataRow^ row = myDataSet->Tables["tblPanel"]->NewRow();
myDataSet->Tables["tblPanel"]->Rows->Add(row);
if (row != nullptr)
{
row["ID"] = dblID;
row["item_id"] = item_id;
row["use"] = use;
row["type"] = Convert::ToInt16(type);
DataAdapter->Update(myDataSet, "tblPanel");
}
Stefan
|
|
|
|
|
I finally found the error that prevented me from adding the data.
I have used this code:
DataTable^ MyTable = myDataSet->Tables[0];
DataRow^ row = MyTable->Rows->Add();
instead of this:
DataRow^ row = myDataSet->Tables["tblPanel"]->NewRow();
Stefan
|
|
|
|
|
Is there a way for me to create a listview hearder spanning 2 rows using C/C++. If there is, then I would appreciate it if someone can provide me with some code snippit.
|
|
|
|
|
try inserting a newline character in header name
|
|
|
|
|
I tried that and it didn't work.
|
|
|
|
|
|
I am not creating an MFC app, just a windows app. I am using the LVCOLUMN structure to create my listview.
|
|
|
|
|
Ok.
The point was, you can use custom draw to achieve this.
It's no different with MFC than without MFC, except where you handle the messages.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi again, I am using Visual Studio 2005 C++/CLI. I have a form that I want to display statistical information. There is a TextBox control on the form named textBox1. When I click on the menu selection to display the statistics form the following code is executed...
private: System::Void waferMapStatisticsToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
Stats^ statistics = gcnew Stats(); // instantiate a new statistics Form object
TextBox^ text_box = gcnew TextBox(); // instantiate a new TextBox object
text_box->Text::set("This is a test");
statistics->textBox1 = text_box; // this does set the value of textBox1 to "This is a test"
statistics->Text::set("DIALOG TITLE STRING"); // this does change the forms title
statistics->ShowDialog();
}
If I step through the code I can see that the value of the textBox1 control on the statistics Form changes, but when I ShowDialog() the statistics Form title changed but there is nothing displayed in textBox1. I have also tried using statistics->Update() and have tried setting the value of textBox1 through a property definiiton. The results are the same. This seems to be trivial and intuitive but alas. Does anyone know why the textBox1->Text is not displaying on the statistics Form?
Thanks
Buck
|
|
|
|
|
Hi Buck,
I don't know what statistics and statistics->textBox1 are.
My best guess is statistics is some kind of Form, and textBox1 is a public field,
of the TextBox^ kind.
If so the question is when do you add textBox1 to the statistics->Controls?
if you do that before you execute statistics->textBox1 = text_box;
then the original textbox is included in your form, and not the one you
intend to substitute just before the ShowDialog().
The solution would be to make textBox1 private (it is not a good idea to
make Controls public, only some aspects of it need to be public at most),
and to provide another public property to set its text.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|