|
Basically my windows service is used to handle a teletext signal reader (essentially receives text over TV broadcasting) via a C api compiled to a dll.
My service continually waits on the feed for new messages. Once a message is received, it is processed, stored to a database and made available for other applications in my domain.
Where I initially thought my memory was getting gobbled up was in my queues used to pass messages between threads, since depending on the throughput of the device, could have up to 18,000 messages (each message object is probably < 100 bytes or so) waiting to be processed. But I did the math and that didn't come close to my 200Mb working set. Essentially one thread puts messages in a queue and another thread waits for messages in the queue, dequeues the message and processes it. There are around 10 such threading setups in the service.
So I'm looking else where for the problem. Somewhere I'm forgetting to deallocate objects. One thing that I'm testing for at the moment is that maybe one of my threads is crashing and the queue of which its supposed to dequeue is filling up. Since the problem doesn't appear until the service has been running longer than 6 hours or more, it's going to take some time to find (which further makes me think that a thread is crashing somewhere).
Failing one of my threads crashing over the weekend I will be looking at that manager heap profiler mentioned above in one of the posts.
Andy
|
|
|
|
|
Thanx, this explains alot more
Andy Davey wrote:
Basically my windows service is used to handle a teletext signal reader (essentially receives text over TV broadcasting) via a C api compiled to a dll.
You seem to constantly marshalling string data to the C# service (as I understand it), are the data being freed afterwards? .Net wont do this for you. It will make yet another copy of it, but managed this time (no worries now).
Also the problem could be in the C code or the way the function being called is meant to implemeted, like said above whether the resulting char* should be freed or not. If you have the C code, you can easily "remedy" this by using a GC (i suggest libGC).
HTH
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Rrrrrright. I'd never considered that.
Yeah the way that I access the API is by passing an uninitialised object which the API initialises (eg GetMesssage(out p_messageDetails);)
Now who's repsonsibility is it to deallocate the memory used in the message? Mine or the marshallers?
I wouldn't even know how to deallocate that memory to be honest . Its amazing how lazy you get when you code under a GC.
Andy
|
|
|
|
|
It sounds like your job
You can try use:
Marshal.FreeHGlobal() , but somehow i dont think that will cut it.
Best approach would be to store the returned pointer, then do a manual marshall to with PtrToStructure, then use the above method to free it.
Good luck
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
On my main form I have a progess bar "progressBar1" (Public).
I have another class file "pb.cs", in which is the code...
using System;
namespace WindowsApplication8
{
public class pb
{
Form1 guid=new Form1();
public pb()
{
guid.progressBar1.Value=100;
}
}
}
Why can I not change the value of the progess bar to 100?
/\ |_ E X E GG
|
|
|
|
|
eggie5 wrote:
Why can I not change the value of the progess bar to 100?
Do you mean that the progress bar doens't visually change or do you mean that the framework throws an exception.
Without seeing more of your code I would suspect its the former one. From what I can see you are expecting this pb class to update the progress bar in the applications main form. However, the pb class has no reference to the main form. When the pb class is created, a new object of type Form1 is created. This new is not the same object as the one displayed on the screen when you run your program. To get your guid member to reference the displayed form - pass a Form1 object reference to the pb constructor.
An example would be
public class Form1
{
pb m_pb;
public Form1()
{
m_pb = new pb(this);
}
}
public class pb
{
Form1 guid;
public pb(Form1 p_ref)
{
guid = p_ref;
guid.progressBar1.Value = 100;
}
}
|
|
|
|
|
it works like a charm. gracias.
but, how would I do this from class "logging.cs" with out direct access to it from the main form "Form1.cs".
understand?
|
|
|
|
|
how would anyone understand... this is too hard to explain.
/\ |_ E X E GG
|
|
|
|
|
You want to update your progress bar from another class, right ?, but you don't want to make a reference to the from that contains the progress bar ?
Is that ???
Free your mind...
|
|
|
|
|
sure... do you think you can help a guy out?
/\ |_ E X E GG
|
|
|
|
|
Sure. Let me build a sample.
Free your mind...
|
|
|
|
|
|
Here it goes...
namespace WindowsApplication1<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private bool _done = false;<br />
private ProgressBar _pb = new ProgressBar();<br />
private Form2 _form = new Form2();<br />
private System.Windows.Forms.Button button1;<br />
private System.Windows.Forms.Button button2;<br />
private int _value=0;<br />
<br />
public Form1()<br />
{<br />
this.Size = new System.Drawing.Size(300,300);<br />
<br />
this.button1= new Button();<br />
this.button1.Location = new System.Drawing.Point(8, 240);<br />
this.button1.Name = "button1";<br />
this.button1.Click += new System.EventHandler(this.button1_Click);<br />
<br />
this.button2= new Button();<br />
this.button2.Location = new System.Drawing.Point(100, 240);<br />
this.button2.Name = "button2";<br />
this.button2.Click += new System.EventHandler(this.button2_Click);<br />
<br />
this.Controls.Add(this.button1);<br />
this.Controls.Add(this.button2);<br />
<br />
this._pb.Location = new Point(0,0);<br />
this._pb.Width = 100;<br />
this._pb.Minimum=0;<br />
this._pb.Maximum=100;<br />
}<br />
<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{ <br />
_form.Show();<br />
<br />
if (!_done)<br />
{<br />
_form.Controls.Add(_pb);<br />
_done=true;<br />
}<br />
}<br />
<br />
private void button2_Click(object sender, System.EventArgs e)<br />
{ <br />
if(_value<100)<br />
_value +=10;<br />
else<br />
_value=0;<br />
<br />
_pb.Value=_value;<br />
}<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
<br />
}<br />
}
I think that's what you want, isn't it ?
Free your mind...
|
|
|
|
|
ok, nevermind... I get it now.
thanks again for your code.
/\ |_ E X E GG
|
|
|
|
|
I made a similar test and I managed to change the progress bar's value to 100.
If you could specify the error message you received it would be very helpful.
You may want to check these things first:
1. Make sure Maximum value for the progress bat is at least 100.
2. Check that the progress bar is declared as PUBLIC in your Form1, otherwise create a property to access your progress bar.
Hope it helps!
|
|
|
|
|
Hello....
I do not recieve any exceptions, but here is what I understand is going on....
when I do this code in in a sperate class....
Form1 guid=new Form1();
apparently it just makes a duplicate of the from Form1. I can completely control this new from from the seperate class, with no problems... if I go guid.Show(); it then displays the duplicate with the controls muniplited, as i configured.
However, I don't want to manipulate the controls (i.e. progress bar) on the dup;icate Form1, I want to do it on the original.
From what I understand so far, I think I have to make a REFERENCE... and yes the progressBar is public.
alos, I do not have access to the Form 1 from the seperate class "logging.cs" because my code eventually gets to that class after going though other classes before it....
does this make sense? is it possible?
thankyou for your time.
/\ |_ E X E GG
|
|
|
|
|
As much trouble as you are having, you may want to invest in
a good book on .Net Threading.
Thank You
Bo Hunter
|
|
|
|
|
i have already expressed intrest of a C# threading book. But, recieved little reply on recomendations. Do you have one?
/\ |_ E X E GG
|
|
|
|
|
that's not exactly what I need. But, thanks for your help. It turned out I had to make a refrence, as opposed to making a new object of the Form...
thanks again.;P
/\ |_ E X E GG
|
|
|
|
|
actually no, I figured it out.
thanks.
/\ |_ E X E GG
|
|
|
|
|
Hi all !! I'm very new to ASP.NET and I have been trying to find a solution to the following problem: I'm building a website and I have to load a list of screen IDs and the corresponding screen names into an application level structure, so it can be accessed from all the pages in my website. I researched a little bit and came to the conclusion that i should implement a DictionaryBase class. All the samples i have seen are quite straightforward. The data gets loaded into memory and a test to obtain a specific entry from the structure are implemented in the same page. In my case, I want to load the structure in one place only once and the data should remain in memory as long as the .NET application is running and structure should be accessible from all the pages. Any pointers on how I can implement this, is greatly appreciated.
Thanks.
Subha.
|
|
|
|
|
Okay, I'm not trying to sound stupid, but is there some reason you shouldn't just use an instance of something like Hashtable or StringDictionary directly? I mean, is there something specific you need out of your new class that isn't supported by the built-in collections?
It sounds like you're not going to be modifying the structure during the life of your application. If so, don't make it synchronized, as this will impair performance a little. But if you will be modifying the data, you should synchronize it. With Hashtable, this can be done very easily:
Hashtable hashtable = Hashtable.Synchronized(new Hashtable());
One more tip: if your hashtable will be read very frequently, you should leave a lot of empty space in it, to minimize the chance of an index collision. You can do this by setting the load factor, or by choosing an initial size that's much bigger (say, double or more) than
the number of expected entries. This should be a really miniscule memory whack, since your object will be shared by the whole application.
You might want to also play around with ADO.NET's caching features. One of the coolest features of .NET is the ability to basically keep an in-memory database, searchable and all. I don't think your problem calls for this, though.
Regards,
Jeff Varszegi
|
|
|
|
|
hi,
I have a question about changing a text(string) to an image(.jpg) in a web page.
I have the code below but when I use it other web controls doesn't initialize??
I mean if I put some text boxes on the .aspx page it doesn't show them only show the .jpg and if I use the code not in page_load it doesn't work,strange isn't it? How can I solve this?
Code:
using System.Drawing;
using System.Drawing.Imaging;
private void Page_Load(object sender, System.EventArgs e)
{
Bitmap b = new Bitmap(250,80);
Graphics g = Graphics.FromImage(b);
SolidBrush sb = new SolidBrush(Color.Green);
Font f = new Font("Arial",12);
g.FillRectangle(new SolidBrush(Color.White),0,0,250,80);
g.DrawString("This is a cool thing",f,sb,5,10);
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
b.Dispose();
}
how can I solve this?
Best wishes,
-
When in doubt, push a pawn!
-
|
|
|
|
|
Of course it doesn't work, you're outputing the image to the page response stream itself! What you need to do instead is to have this in a separate page and the first page references that in an IMG tag, along with possible parameters (as a query string) to control what text is output (and/or size, etc.). You've got the right idea, but you need to remember that the page and the files (images, scripts, stylesheets) are all separate references to different files. You can't combine them (generally speaking, not without MIME at least).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks!it worked
-
When in doubt, push a pawn!
-
|
|
|
|