|
Hi,
I have some collection that hold some struct.
Its look like this :
struct PointColor
{
Point p;
Color c;
public PointColor(Int32 x, Int32 y, Color c)
{
p = new Point( x, y );
this.c = c;
}
};
private List<PointColor> PointColorCollection = new List<PointColor>();
My Question is:
Because the object in the collection are value type - does this collection cleaning can cause somehow the GC to run ?
If the answer is 'Yes' - is there some way to optimize this code and avoid GC to run ?
Thanks.
|
|
|
|
|
Do yourself a favor, and just don't worry about it. The garbage collector works beautifully in almost all situations. As long as you keep a reference to it, no matter how indirect, it won't be trashed. Whether it's a class or struct doesn't really matter.
|
|
|
|
|
It's next question about manipulating GC in last few days... Sometimes I have the feeling, that some people think, that if they force GC to work they are better developers... What for? If application uses to much memory it's probably your fault, not the GC not working properly.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
There seems to be some kind of wide spread incomfort (lacking a better term in the moment) with this basic concept of CLR. What I see is a lot of folks who are simply told "tommorrow, you start writing .NET code"... So they do start applying the 'learning by doing' method...
|
|
|
|
|
Yanshof wrote: does this collection cleaning can cause somehow the GC to run ?
No.
However not the no you are hoping for: the GC will run when you either force it to run (say calling GC.Collect, a bad idea) or when you do something (typically execute a new Something) that needs more memory than is currently available. Freeing/clearing something will not cause the GC to run (except when you would be extremely nasty and have objects that allocate new stuff in their finalizer, a horrible thought it is).
I think you have been asking the wrong question. Either you are worried about performace or you already are having performance trouble. Then you should give more contextual information and ask a more open question.
The code shown basically represents a pixel; I do hope you are not using that to construct an entire image.
|
|
|
|
|
I don't understand your questions... First you ask if "cleaning" a collection causes GC to run. - Answer is Maybe... Because GC is hardly predictable and depends on the memory use of your whole application. You can force garbage collection with GC.Collect - but this is not good practice...
Then you say you want to avoid GC to run? And what the hell you mean with "because the objects in the collection are value types"?
Maybe you tell us what your problem is? Performance, memory, general interest? How many values will be in the collection and what you mean with "cleaning"?
|
|
|
|
|
1. my problem is performance.
My application need to deal with a lot of data that comes from some other application and i afraid that if the GC will start run - then i will miss some of the packages that the other application is sending to me.
2. The collection is holding ~100000 items.
3. Beside this, i what to know better how the GC is working ( under the hood ) and i still have open question about it ( and still i don't understand some issues ).
This is why i asking so many question on the last couple of days about the GC and how its work.
|
|
|
|
|
@1: Don't worry, as long as you keep a reference to your data GC will not free any memory. I don't understand how you can "loose data" because of the GC? If you loose your reference to the data, it's lost anyway...
@2: Maybe here's the root of your perfomance problems? Depends on what you are doing with your collection...
Think about your application architecture (Maybe you don't have to hold all this items in memory?)
@3: Coming from years of manual memory handling with C/C++, and using .NET now since Version 1.0, I can tell you there were hardly any circumstances when I wanted to handle the
memory allocation/freeing for myself again. From my view the GC works pretty perfect, and the best thing: You don't have to know much about it. Whenever I ran into memory-related performance problems it was because of wired requirements or bad designed application architecture. First make shure you got this right, and if memory-handling is still the problem you may want to do some tricks with "unsafe" or "native code", at least the critical parts? Or use some other technics like memory-mapped-file etc. (do a search here on codeproject)
|
|
|
|
|
Hello All,
I am scraping some text from a html page and writing to a text file.
after every line extraction i am adding the text to list & in the end i am writing to a text file.
in one pass i am getting text as
Email: ptadeep.g@someemail.com Membership Type:
in this line i want only the email id , Please is there any method to remove the words Email & Membership Type from the string and then add only email id to list ??
|
|
|
|
|
|
Thanks Richard for the response.
I tried with
IndexOf ,LastIndexOf & str.Substring methods and got the output.
|
|
|
|
|
if you have problems dealing with strings, the natural approach is to read up on the String class. It has a lot of methods, and whatever your problem is, there will be one or more solutions.
|
|
|
|
|
Regex is your friend.
/ravi
|
|
|
|
|
Substring, Regex, IndexOf.
|
|
|
|
|
I want a really nice simple way to grab textures from folders so that I don't have to read there data in all the time in XNA.
The idea will be to load all the textures in my content folder and its sub folders (such as Content\Sprites) so that at run time I could use something such as :
mytexture = Texture.GetTexture("Sprites","myspritefile");
The problem is that I am not sure if this "global" method of grabbing files is recommended?
|
|
|
|
|
|
Thanks
|
|
|
|
|
Good question. I am currently working on a graphics engine under XNA and also would prefer to load graphics resources from folders. Otherwise the graphics resources will fill a very fat library.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
.. O.k., So there are a couple of potential issues here...
First remember your memory limitations, so sure you can do it as long as your supported hardware can accommodate it. but there is really no good reason to waste all that memory...
You may want to look into sprite maps...
There really isn't a need to run mytexture = Texture.GetTexture("Sprites","myspritefile"); to load ALL content.. remember that it is compiled in the content pipeline, and put into hard disk location (by basically a reference value).. so at any time during Update , you use:mytexture = Texture.GetTexture( "Sprites", "myspritefile"); anyways. the "preferred" method would be to load on a separate thread.
Alternatively, (try an in game load, you probably don't even need a separate thread to do this....) Unless your loading A LOT of LARGE content at once and you need it to be snappy, in which case load all the content for that "cycle" of the game... I.e: Loading screen, main menu, pause menu, game tiles/sprites, Death Screen, Victory screen,... such that when you complete a level, or one unit of game play, you may hit a loading screen(underlined) or animation etc... that displays in the approximate amount of time it takes to swap out the particular level game tiles/sprites... you can even load the victory and death scenes while the game is in 'play' mode to save the user the headache of waiting for *all* the images to be loaded...
I would say experiment with loading content at different times until you get a combination of Content loading locations in your code, which will allow the UI to be responsive and minimize load times... remember that when you want to sell it you will be "graded" on how responsive the UI is and how long it takes to load (the trial level/scenario)... So if your game is mature enough I would optimize to trial mode, and then tweak to normal mode (if need be)..
I'd blame it on the Brain farts.. But let's be honest, it really is more like a Methane factory between my ears some days then it is anything else...
|
|
|
|
|
guys i need to create a small application for turning on my computer at a given time.
lets say now it is 8.00Pm and i need to turn on my computer when the system time is equal to 10.00 Pm ..
so can any body help me to develop this program!
|
|
|
|
|
If there's no power, then you can only switch it on if you write a program to control a robot hand to switch it on.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
...and hope the robot hand has power available to it too.
|
|
|
|
|
Only a few little problems here.
1) When the power is off, the processor is not running. This means that your program is not running either.
2) See 1.
You will need external hardware - wake on LAN, external mains on switch, or similar. You can't do it with software, sorry.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
If your computer isn't running, you can't run a program on it.
You can put it to sleep and have a windows service running that will wake it up at a certain time, but that's the best you can do.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Is your computer on the network? Does your motherboard support Wake-On-LAN? if so, you can send magic packet to wake your computer up. Once it is up, it is not hard to shut-it down. see here[^]
|
|
|
|