|
I think it is implementation-specific. The VM doesn't explicitly call free() on those objects. Instead, it caches the memory for further reuse in order to cope with malloc() overheads. But, if I leave my app idle for a while, the memory is slowly released. Same thing is also observed in Oracle's Java VM for windows.
Beauty cannot be defined by abscissas and ordinates; neither are circles and ellipses created by their geometrical formulas.
Source
|
|
|
|
|
Task Manager is showing you the memory the the .NET CLR has RESERVED for your application, not how much it's actually using. The same goes for VMMAP. Neither tool goes into any of the details of the managed runtime memory manager.
If you want to see how much memory your app is really using at any point in time, open PerfMon and use the .NET Memory counters in there.
The memory that your application uses, when freed, gets returned to the Managed Heap in the .NET CLR, not to Windows. This is because allocations for future objects are faster is there is memory available in the managed heap. If not, then a block of memory has to be allocated from Windows, put in the managed heap, then your object allocated. This takes more time.
Unless you're really worried about how much memory your app is actually using, you're worried about nothing. The .NET CLR memory manager is very good at it's job and tunes itself depending on how your app is running. It's constantly watching how your app allocates and frees memory and adjusts the size of the managed heap every once in a while. But, if Windows needs the memory back, the .NET CLR will happily return any memory it can to Windows.
|
|
|
|
|
Thanks Dave!
The problem was in RaptorDB when I was inserting 100K docs into it which uses around 600Mb of ram, this was fixed by freeing internal cache data after saving to disk which brought it back down to around 150Mb, however restarting the app with the same data files only uses 70Mb and works like a charm, so I was perplexed where the difference was since I released all my cached data.
Anyway the problem of memory usage is fixed but I still get a nagging feeling about the difference.
A programmer walks into a bar and asks the bartender for 1.00000000000003123939 root beers. Bartender says, I'll have to charge you extra, that's a root beer float. Programmer says, better make it a double then.
|
|
|
|
|
That "diamond reply," imho, Dave, deserves to be enshrined in a Tip-Trick.
yours, Bill
~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal
|
|
|
|
|
I should do that. It's an answer that comes up time and time again.
The problem is how to get it to show up when a user does NOT Google for it!
|
|
|
|
|
GC.WaitForPendingFinalizers may help. I needed it in some cases, when I experieced OutOfMemory exceptions despite calling GC.Collect.
|
|
|
|
|
Do GC.Collect() for reasearch reasons and so on.
But for real life applications its not an good idea, because it blocks all threads.
I do GC.Collect() only on 32 Bit machince, in situations where i encounter a OutOfMemory Exception, or in situations where i know, that chances are very high that the next lines of code will run into out of memory.
|
|
|
|
|
Hello. I always wonder that how to keep users' GUI updated. I mean how a software should reflect its database fast and efficiently. I generally deal with this problem using a timer checking db every 20-30 seconds but i think it slows down my programs. I would prefer it like filesystemwatcher control. It realizes all files immmediately in folders and doesnt slow down applications at all.
|
|
|
|
|
leone wrote: I always wonder that how to keep users' GUI updated. You're not the first with this idea, and there's a good reason why most applications don't behave that way.
leone wrote: I mean how a software should reflect its database fast and efficiently. The software never loads the entire database with the user looking at the entire database. It's always a part of the data that the user looks at, and usually they work with a snapshot - not with data that changes under their cursor.
leone wrote: I generally deal with this problem using a timer checking db every 20-30 seconds but i think it slows down my programs. How is it implemented? Just refetching the entire dataset? That'll not only slow down your program, it'll slow down the network. How about putting a timestamp in there that holds the last modification-datetime? You could fetch that every N seconds, and fetch the data once it changes.
leone wrote: I would prefer it like filesystemwatcher control. It realizes all files immmediately in folders and doesnt slow down applications at all. The FSW does slow the machine down. You could put each table in a CSV file and host them from a directory - that way you could use the FSW with your data
OTOH, you'd lose all the benefits from having a database.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks Eddy. I generally dont keep sql connection open. I open it once i need. so to do what you told me, i have to open an sql connection, read a table (modification dates table) and close it again. When i do so in every 20 seconds, i have a concern that the application will slow down. I notice that some programs that i use at work reflect changes immediately. I dont think that they check this modification table every 1 second. I am curious about this.
|
|
|
|
|
leone wrote: I generally dont keep sql connection open. Never said you did
leone wrote: When i do so in every 20 seconds, i have a concern that the application will slow down. Yes, that will slow the app, the database-server and the network.
leone wrote: I notice that some programs that i use at work reflect changes immediately. Not by pushing the entire database, and I doubt that the database pushes information to each connected client. You can poll as I already described, simulating the push.
leone wrote: I dont think that they check this modification table every 1 second. It matters little how often they check that table; it's simply more efficient than fetching an entire table.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi leone. Some DBs, such as SqlServer, allow create files. So you could write a trigger that creates a file when a table was updated. Then with the FileSystemWatcher you can refresh the UI.
I hope that helps you.
|
|
|
|
|
code for window form application to change background color using random function
anser please
Regards
Pintu Kumar
|
|
|
|
|
Easy enough, it you just generate a random number for Red, Green and Blue values, then feed those to Color.From(int, int, int)[^] to get a Color back from it. You should know what to do with that I think.
No, we're not writing your code for you.
|
|
|
|
|
You already asked this in QA. Please do not cross post.
|
|
|
|
|
Generating a random colour is easy,
Color.FromArgb(random.Next() | ~0x00FFFFFF)
~0x00FFFFFF is a trick to write unchecked((int)0xFF000000), and the bitwise OR with that value sets the Alpha component to 255 (ie, fully opaque).
It's the "most random" way to generate a colour, that is, each of the 16777216 opaque colours is generated with equal probability. Unfortunately, most of those colours look like poo.
The solution is to generate a random colour in HSV space,
Color.FromArgb(HSV2RGB(random.NextDouble(), 1, 1))
static int HSV2RGB(double h, double s, double v)
{
int h_i = (int)(h * 6);
double f = h * 6 - h_i;
double p = v * (1 - s);
double q = v * (1 - f * s);
double t = v * (1 - (1 - f) * s);
double r, g, b;
switch (h_i)
{
default:
r = v; g = t; b = p;
break;
case 1:
r = q; g = v; b = p;
break;
case 2:
r = p; g = v; b = t;
break;
case 3:
r = p; g = q; b = v;
break;
case 4:
r = t; g = p; b = v;
break;
case 5:
r = v; g = p; b = q;
break;
}
return (-0x01000000 | ((int)(255 * r) << 16)) | (((int)(255 * g) << 8) | (int)(255 * b));
}
-0x01000000 is yet an other trick to write unchecked((int)0xFF000000).
When generating multiple colours, this method still sort of fails: it will produce clashing colours. To avoid that, start with a random colour and add a specific offset
double h_colour = random.NextDouble();
for (int i = 0; i < colours.Length; i++)
{
colours[i] = Color.FromArgb(HSV2RGB(h_colour, 1, 1));
h_colour = (h_colour + 0.618033988749895) % 1;
}
modified 15-Jul-13 14:28pm.
|
|
|
|
|
harold aptroot wrote: ~0x000000FF ~0x00FFFFFF is a trick to write unchecked((int)0xFF000000)
FTFY
(~0x000000FF gives 0xFFFFFF00)
|
|
|
|
|
I can actually not believe I did that. WTF. It's on the level of 1+1=3.
|
|
|
|
|
Sounds like homework to me but here's a couple of clues:
Random myRandom = new Random();
int randomNumber = myRandom.Next(101);
Now, how could I take my randomNumber and select a colour based on that value..?
Perhaps you could do a little research into system.drawing.color?
Then I need to do something like the code below to change the background colour...
this.BackColor = System.Drawing.Color.Red;
|
|
|
|
|
when I add a data Source to Combo Box but when I Run program I get an err :
'O:\C#\School\School\School\bin\Debug\bin\Debug\TabrizKarDB.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
if U get it , there is two of this : \bin\Debug\bin\Debug\
but in Directory I have One !!!!
why i get that err ?
|
|
|
|
|
Because you mistyped the path somewhere??
There's no way for us to tell you what the problem is because we can't see your code, your screen, your hard drive contents, or read your mind!
You have to show us the code here, inside HTML PRE tags, for us to tell you what went wrong.
|
|
|
|
|
I need to instatiate a dictionary accepting null as value, but I have a syntax problem:
Dictionary<string, double[]?> d = new Dictionary<string, double[]?>()
d.Add("a", new double[2]{100,102});
d.Add("b", null);
d.Add("v", new double[2] { 99, 101 });;
Is it possible to do it?
|
|
|
|
|
What happens when you try?
Use the best guess
|
|
|
|
|
You don't need the '?' at all - you need that to specify a value type that can hold a null value. Reference types automatically can (as this is the default value for a reference type variable)
All arrays are reference types, regardless of whether they are array of reference or value types. So what you need to say is:
Dictionary<string, double[]> d = new Dictionary<string, double[]>();
d.Add("a", new double[2] { 100, 102 });
d.Add("b", null);
d.Add("v", new double[2] { 99, 101 });
You would only need the '?' if you wanted an array of doubles that could hold null values, and then the syntax would be:
double?[] da = new double?[10]; To indicate that the individual elements of the array could contain nulls.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Thanks in this way I'm not able to find the Max value of first element
var ks = d.Max(v => v.Value[0]);
I didn't clarify before this port sorry
|
|
|
|