473,468 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Garbage collection (Urgent issue)

How can I make sure that a spicific function location in memory will not
moved , by OS/Garbage collection ?????
The problem is : I'm using a DLL this dll have an call backerror function,
in my Application I made an error function which show the error if occurred
(Message box). I send a reference of my Application error function to DLL
call backerror function.
Now every time an error occur in DLL the DLL call my Application error
function.
This mechanism is working , but after some time some how I receive an
exception ,it looks like the Application error function is not in the same
place. and the DLL can't call it again. How can I make sure my Application
error function will not moved , by OS/Garbage collection ?????
This mechanism used a lot in my work, specially when DLL is a low level
writing in(C++/C) and we use C# for a high level (GUI), we want all the error
be handled by high level (Out put message, logfile , re connect low level
(hardware) ...).

Nov 17 '05 #1
6 1376
On 2005-04-03, Yosi <Yo**@discussions.microsoft.com> wrote:
How can I make sure that a spicific function location in memory will not
moved , by OS/Garbage collection ?????
The problem is : I'm using a DLL this dll have an call backerror function,
in my Application I made an error function which show the error if occurred
(Message box). I send a reference of my Application error function to DLL
call backerror function.
Now every time an error occur in DLL the DLL call my Application error
function.
This mechanism is working , but after some time some how I receive an
exception ,it looks like the Application error function is not in the same
place. and the DLL can't call it again. How can I make sure my Application
error function will not moved , by OS/Garbage collection ?????
This mechanism used a lot in my work, specially when DLL is a low level
writing in(C++/C) and we use C# for a high level (GUI), we want all the error
be handled by high level (Out put message, logfile , re connect low level
(hardware) ...).


hmmm... Are you maintaining a reference to the callback delegate that
is passed to the dll? Because if your not, your going to have issues
after a gc :)

--
Tom Shelton [MVP]
Nov 17 '05 #2
Yes I maintaining a reference to the callback delegate that is passed to the
dll.
"Tom Shelton" wrote:
On 2005-04-03, Yosi <Yo**@discussions.microsoft.com> wrote:
How can I make sure that a spicific function location in memory will not
moved , by OS/Garbage collection ?????
The problem is : I'm using a DLL this dll have an call backerror function,
in my Application I made an error function which show the error if occurred
(Message box). I send a reference of my Application error function to DLL
call backerror function.
Now every time an error occur in DLL the DLL call my Application error
function.
This mechanism is working , but after some time some how I receive an
exception ,it looks like the Application error function is not in the same
place. and the DLL can't call it again. How can I make sure my Application
error function will not moved , by OS/Garbage collection ?????
This mechanism used a lot in my work, specially when DLL is a low level
writing in(C++/C) and we use C# for a high level (GUI), we want all the error
be handled by high level (Out put message, logfile , re connect low level
(hardware) ...).


hmmm... Are you maintaining a reference to the callback delegate that
is passed to the dll? Because if your not, your going to have issues
after a gc :)

--
Tom Shelton [MVP]

Nov 17 '05 #3
If both the application and the DLL are written using managed code then you
must be releasing the reference or disposing of something by mistake. GC
might move the objects in memory but the system will update the references
automatically and you won't "loose" one.

If the DLL is not managed code however, which is the case in some of your
application it seems, you may need to consider pinning objects that you pass
to the DLL by pointer/IntPtr to prevent them from moving. See
Marshal.GCHandle and/ or Marshal.UnsafeAddrOfPinnedArrayElement for details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
How can I make sure that a spicific function location in memory will not
moved , by OS/Garbage collection ?????
The problem is : I'm using a DLL this dll have an call backerror function,
in my Application I made an error function which show the error if
occurred
(Message box). I send a reference of my Application error function to DLL
call backerror function.
Now every time an error occur in DLL the DLL call my Application error
function.
This mechanism is working , but after some time some how I receive an
exception ,it looks like the Application error function is not in the same
place. and the DLL can't call it again. How can I make sure my Application
error function will not moved , by OS/Garbage collection ?????
This mechanism used a lot in my work, specially when DLL is a low level
writing in(C++/C) and we use C# for a high level (GUI), we want all the
error
be handled by high level (Out put message, logfile , re connect low level
(hardware) ...).

Nov 17 '05 #4
How can I make my DLL to be compiled using managed code option ?

"Bob Powell [MVP]" wrote:
If both the application and the DLL are written using managed code then you
must be releasing the reference or disposing of something by mistake. GC
might move the objects in memory but the system will update the references
automatically and you won't "loose" one.

If the DLL is not managed code however, which is the case in some of your
application it seems, you may need to consider pinning objects that you pass
to the DLL by pointer/IntPtr to prevent them from moving. See
Marshal.GCHandle and/ or Marshal.UnsafeAddrOfPinnedArrayElement for details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
How can I make sure that a spicific function location in memory will not
moved , by OS/Garbage collection ?????
The problem is : I'm using a DLL this dll have an call backerror function,
in my Application I made an error function which show the error if
occurred
(Message box). I send a reference of my Application error function to DLL
call backerror function.
Now every time an error occur in DLL the DLL call my Application error
function.
This mechanism is working , but after some time some how I receive an
exception ,it looks like the Application error function is not in the same
place. and the DLL can't call it again. How can I make sure my Application
error function will not moved , by OS/Garbage collection ?????
This mechanism used a lot in my work, specially when DLL is a low level
writing in(C++/C) and we use C# for a high level (GUI), we want all the
error
be handled by high level (Out put message, logfile , re connect low level
(hardware) ...).


Nov 17 '05 #5
Is the DLL in C++? Have you tried compiling the source with VS.NET?

Without knowing a lot more about your problem it's hard to advise you.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.com...
How can I make my DLL to be compiled using managed code option ?

"Bob Powell [MVP]" wrote:
If both the application and the DLL are written using managed code then
you
must be releasing the reference or disposing of something by mistake. GC
might move the objects in memory but the system will update the
references
automatically and you won't "loose" one.

If the DLL is not managed code however, which is the case in some of your
application it seems, you may need to consider pinning objects that you
pass
to the DLL by pointer/IntPtr to prevent them from moving. See
Marshal.GCHandle and/ or Marshal.UnsafeAddrOfPinnedArrayElement for
details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
> How can I make sure that a spicific function location in memory will
> not
> moved , by OS/Garbage collection ?????
> The problem is : I'm using a DLL this dll have an call backerror
> function,
> in my Application I made an error function which show the error if
> occurred
> (Message box). I send a reference of my Application error function to
> DLL
> call backerror function.
> Now every time an error occur in DLL the DLL call my Application error
> function.
> This mechanism is working , but after some time some how I receive an
> exception ,it looks like the Application error function is not in the
> same
> place. and the DLL can't call it again. How can I make sure my
> Application
> error function will not moved , by OS/Garbage collection ?????
> This mechanism used a lot in my work, specially when DLL is a low level
> writing in(C++/C) and we use C# for a high level (GUI), we want all the
> error
> be handled by high level (Out put message, logfile , re connect low
> level
> (hardware) ...).
>


Nov 17 '05 #6
No I compiled it using MFC, VS 6 . I'ts a simple dll, Export/Import functions.
"Bob Powell [MVP]" wrote:
Is the DLL in C++? Have you tried compiling the source with VS.NET?

Without knowing a lot more about your problem it's hard to advise you.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.com...
How can I make my DLL to be compiled using managed code option ?

"Bob Powell [MVP]" wrote:
If both the application and the DLL are written using managed code then
you
must be releasing the reference or disposing of something by mistake. GC
might move the objects in memory but the system will update the
references
automatically and you won't "loose" one.

If the DLL is not managed code however, which is the case in some of your
application it seems, you may need to consider pinning objects that you
pass
to the DLL by pointer/IntPtr to prevent them from moving. See
Marshal.GCHandle and/ or Marshal.UnsafeAddrOfPinnedArrayElement for
details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
> How can I make sure that a spicific function location in memory will
> not
> moved , by OS/Garbage collection ?????
> The problem is : I'm using a DLL this dll have an call backerror
> function,
> in my Application I made an error function which show the error if
> occurred
> (Message box). I send a reference of my Application error function to
> DLL
> call backerror function.
> Now every time an error occur in DLL the DLL call my Application error
> function.
> This mechanism is working , but after some time some how I receive an
> exception ,it looks like the Application error function is not in the
> same
> place. and the DLL can't call it again. How can I make sure my
> Application
> error function will not moved , by OS/Garbage collection ?????
> This mechanism used a lot in my work, specially when DLL is a low level
> writing in(C++/C) and we use C# for a high level (GUI), we want all the
> error
> be handled by high level (Out put message, logfile , re connect low
> level
> (hardware) ...).
>


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Larsen [] | last post by:
Hi, I'm trying to figure out what triggers the GC to run in dotNet 2.0. Please explain how it works ! Thank you in advance. BR Peter
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
17
by: andreas.eisele | last post by:
I should have been more specific about possible fixes. In a related thread on http://bugs.python.org/issue2607 Amaury Forgeot d'Arc suggested a setting of the GC thresholds that actually...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.