garbage collection and calling dll's (eg win32 api)

G

Guest

Hi,

I have a few related questios:

1. if I pass a string to win32 api (or other dll not written in .net), is it
possible GC cleans up while function is still busy ? eg:

public class Win32
{
[DllImport("User32.dll")]
public static extern IntPtr FindWindow(string ClassName, string
WindowName);

And call it:

IntPtr Win = Win32.FindWindow(ClassName, null);

2. Does it make a difference if ClassName is a literal inside the exe,
because in that case the string is only a pointer to something in read only
mem, so no memory allocation, eg:

string ClassName = "theclass";
IntPtr Win = Win32.FindWindow(ClassName, null);

3. Is it possible to block the GC for a while, for example if I have time
critical code to execute, I dont want to let GC slow down machine if there is
a lot to clean up ?
 
M

Mattias Sjögren

Wilfried,
1. if I pass a string to win32 api (or other dll not written in .net), is it
possible GC cleans up while function is still busy ?
No.


2. Does it make a difference if ClassName is a literal inside the exe,
No


because in that case the string is only a pointer to something in read only
mem, so no memory allocation, eg:

The string is still allocated from the GC heap.

3. Is it possible to block the GC for a while, for example if I have time
critical code to execute,
No.


I dont want to let GC slow down machine if there is
a lot to clean up ?

I wouldn't worry about that unless you've actually measured the time
used by GC and determined that it's a problem.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top