|
yes i m doing nothing wrong because i just got the dll of directx sound and referenced it.
will u plz let me knw how can i disable the MDA...
|
|
|
|
|
Debug->Exceptions->Managed Debugging Assistants, then uncheck the "LoaderLock" option.
|
|
|
|
|
I'm using the following code to create an instance of a Type:
Activator.CreateInstance(propertyType) // Where propertyType is a Type
This seems to work fine for the majority of types but when I attempt to use it for a string I get the following error:
No parameterless constructor defined for this object.
I've been looking high and low for any examples or documentation on the how to do this and haven't been able to find anything.
Can anybody help and save my sanity?
|
|
|
|
|
|
Activator.Create instantiates an object using its default constructor. As you can see here[^], string has no default constructor. Activator.Create is probably identical to the following:
public object CreateInstance(Type objType) {
ConstructorInfo ci = objType.GetConstructor(Type.EmptyTypes);
if (ci == null)
throw new Exception("No parameterless constructor defined for this object.");
return ci.Invoke(null);
} You will need to have special cases for classes that do not implement a default constructor, either by extending the classes with extension methods (if you have .Net 3.0 or above), or by using a try/catch to catch the exception and instantiate those classes yourself. Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I guess the reason is that string class has not got public default constructor. You can try either using other overload of CreateInstance or create an instance of StringBuilder class.
|
|
|
|
|
|
Good day
I've been experimenting a bit with the DataGridView, and its memory usage. If you add a high amount of rows to the grid, and then clear it, it apparently won't clear its memory as well. It's as if the rows are still in the memory, but dereferenced. When you populate the grid again, with alot of data, the memory usage keeps on going up, as if he now has two lists of rows. This goes on for a while every time I clear and populate again, until the memory usage gets to a certain amount, then the application freezes for a very short while (some milliseconds) and the memory usage gets reduced back to the normal level of one populated DataGridView.
This is just the GC doing its work, but I didn't know he did it that sporadicly. He also doesn't seem to work in function of time, but in function of total memory usage. He watches how high the memory usage goes, and when it gets to a certain level he finally starts working.
The method GC.Collect() solves this all of course. So now my question is, when you're working with DataGridViews and a high amount of data, is it recommended to actually just always do a GC.Collect after you cleared the grid?
Thanks in advance.
|
|
|
|
|
Jitse wrote: This is just the GC doing its work, but I didn't know he did it that sporadicly. He also doesn't seem to work in function of time, but in function of total memory usage. He watches how high the memory usage goes, and when it gets to a certain level he finally starts working
It is a function of memory usage.
Jitse wrote: The method GC.Collect() solves this all of course. So now my question is, when you're working with DataGridViews and a high amount of data, is it recommended to actually just always do a GC.Collect after you cleared the grid?
Generally GC.Collect() shouldn't be used. You should allow the garbage collector to figure out the optimisation.
I would guess that the slowness is due to a high number of very small objects being cleared up.
|
|
|
|
|
I've got a testing application, that has about 57MB of memory usage with filled DataGridView. Now the GC only starts working at about 200MB. That's quite alot. I'd rather have an application using 57MB all the time, instead of always getting to 200MB before optimization starts to get it back to 57MB.
|
|
|
|
|
The .NET 2.0 Service Pack 1 adds some new APIs to help you control this behavior. Look up System.Runtime.GCSettings class.
|
|
|
|
|
I've got .NET Framework 2 SP1, and I don't see anything interesting in that class. All it has are these two properties:
// Gets a value indicating whether server garbage collection is enabled.
System.Runtime.GCSettings.IsServerGC
// Sets the behavior of the GC
System.Runtime.GCSettings.LatencyMode
The LatencyMode could be interesting, if it wouldn't only have these three unusable choices:
GCLatencyMode.Batch // for non-UI applications
GCLatencyMode.Interactive // for UI applications, used by default
GCLatencyMode.LowLatency // when you don't want the GC to interrupt time-sensitive operations
Nothing interesting there.
Edit: On MSDN it says this:
Use the Collect method when there is a significant reduction in the amount of memory being used at a defined point in your application's code. For example, if your application uses a complex dialog box that has several controls, calling Collect when the dialog box is closed could improve performance by immediately reclaiming the memory.
If they already think a complex dialog box is a good situation to collect garbage after with GC.Collect, I think a DataGridView with a hundred thousand rows that has been cleared is a good reason too. That's just my unexperienced opinion though.
modified on Tuesday, February 26, 2008 3:36 PM
|
|
|
|
|
You could try Batch to see if it solves anything, might be interesting to note.
FWIW, we've had a problem with the garbage collector here where our server app will use 500-700MB of memory before the garbage collector kicks in and brings it back down to 80MB. We've even had occassions where the app will be eating 1GB+ of memory and starts throwing OutOfMemoryExceptions until we force a GC. It's really insane. Unfortunately, the only way we were able to get around this is to force a GC key spots in the code. This isn't typical -- we've never seen the above issue on any other applications, so it may be a bug in our code somehow...
We shouldn't have to do this, and sometimes I wonder if the GC is being too lazy, or in the above case, not working at all.
Oddly, if I force 1 or 2 garbage collections, the GC seems able to handle everything from there on out.
I guess I'd recommend forcing a GC in rare scenarios like the one you describe above, where lots of memory suddenly is freed and should be collected immediately.
|
|
|
|
|
Alright, seems the GC isn't 100% perfect yet. Thanks for the reply.
|
|
|
|
|
Hi,
I have written code for sending mails using c#.I am facing the following problem with this.
Mail Body is not showing up for Meeting requests/mail received through Lotus Notes. The meeting request is shown correctly when viewed through the Outlook with the body showing up but not in Lotus Notes.
Plz help me...
Thanks in Advance
Alok...
|
|
|
|
|
It's difficult to help if you don't show us some code.
|
|
|
|
|
Here is the code i am using,
msg.From = new MailAddress(From);
msg.Subject = Subject;
msg.SubjectEncoding = System.Text.Encoding.Default;
StringBuilder strBodyText = new StringBuilder();
strBodyText.AppendLine(some string on logical criteria);
msg.Body = strBodyText.ToString();
msg.BodyEncoding = System.Text.Encoding.Default;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Port = 25;//or use 587
client.Host = smtpServer;
client.Send(msg);
|
|
|
|
|
Ok, looks pretty good to me. Do other applications have issues downloading these emails?
|
|
|
|
|
No I am facing this issue with Lotus Notes only.
|
|
|
|
|
Sounds like you need to talk to Lotus Notes support, given that you're code looks fine and it works with other email clients.
|
|
|
|
|
|
hey peeps
can someone please BRIEFLY explain the word "memory leak" to me?
ive come across something strange in a test app im writing, im communicating to a external device via LAN using an SDK provided by the manufacturer. The documentation keeps commenting parts of code "Critical! Without disposing, you'd have a memory leak."
what happens in my app is sometimes i close it but visual studio stays in debug mode? is this a memory leak?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
|
A memory leak means your program or library is allocating memory and never freeing it. Since the CLR managed memory for you, this shouldn't be an issue. But there are some things to watch out for:
if you you objects that implement IDisposable, you should call Dispose on them when you're done. Read up on IDisposable[^].
Another thing to watch out for is listening for events on live objects. Say you have an object that will be around for the program's duration, longLivingObject. It has an event called Changed on it. Now imagine you create 1,000,000 short lived objects during the duration of the program. Each one listens for the Changed event on longLivingObject. Now you'll have a leak: all the shortLivedObjects will stay in memory because the longLivedObject is holding a reference to each shortLivedObject through the event. longLivedObject is keeping the 1,000,000 short lived objects in memory.
|
|
|
|
|
Hi,
i have troubles with a C# wrapper for one of my libraries. The C declaration looks like this:
int find(void *h, void *reserved, key *key, record *record, int flags);
The function searches a database for "key" and, if successfully, fills "record" with the values. In C# record structure looks like this (the only important members are "size" and "data").
[StructLayout(LayoutKind.Sequential)]
unsafe struct RecordStruct
{
public Int32 size;
public void *data;
public Int32 flags;
public Int32 _flags;
public Int64 _rid;
}
And here is my C# function wrapper:
[DllImport("database.dll", EntryPoint = "find",
CallingConvention = CallingConvention.Cdecl)]
static private extern int FindLow(IntPtr handle, IntPtr reserved,
ref KeyStruct key, ref RecordStruct record, int flags);
static public unsafe byte[] Find(IntPtr handle, byte[] data, int flags) {
KeyStruct key = new KeyStruct();
RecordStruct record = new RecordStruct();
key.size = (short)data.GetLength(0);
fixed (byte* bk = data) {
key.data = bk;
int st = FindLow(handle, IntPtr.Zero, ref key, ref record, flags);
if (st == 0) {
return record.data;
}
throw new DatabaseException(st);
}
}
My problem is that RecordStruct.data is a void* byte array, and RecordStruct.size is the size of the array. But how can i create a C# byte[] from this pointer?
If possible, i would like to avoid copying the array contents, which would mean a huge performance penalty (but that would also mean that the void* pointer must not be moved around by the garbage collector...)
Thanks
Christoph
|
|
|
|
|