473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Garbage Collector - Prevent object from being moved

SB
What is the best way to prevent an object from being moved by the garbage
collector (for the lifetime of an application)? Pinning seems to be
designed for temporary operations...so I guess that's not an option.

The reason I'm ask is because I have a class that contains many delegates
that are used as callback functions to a C dll. The dll may call any one of
these delegates at any time...so their addresses must be set in stone until
the app is closed.

I believe I can allocate the object on the stack to prevent it from being
affected by the garbage collector..but I'm not sure if that will work or how
to go about doing it.

Any info would be appreciated!

TIA,
sb
Nov 16 '05 #1
2 1974
You are calling functions (that is JITted code) and this isn't stored in the
GH heap, and as such doesn't 'move'.

Willy.

"SB" <st********@yahoo.com> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
What is the best way to prevent an object from being moved by the garbage
collector (for the lifetime of an application)? Pinning seems to be
designed for temporary operations...so I guess that's not an option.

The reason I'm ask is because I have a class that contains many delegates
that are used as callback functions to a C dll. The dll may call any one
of these delegates at any time...so their addresses must be set in stone
until the app is closed.

I believe I can allocate the object on the stack to prevent it from being
affected by the garbage collector..but I'm not sure if that will work or
how to go about doing it.

Any info would be appreciated!

TIA,
sb

Nov 16 '05 #2
SB
Excellent point!

Thanks
sb

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:un****************@TK2MSFTNGP14.phx.gbl...
You are calling functions (that is JITted code) and this isn't stored in
the GH heap, and as such doesn't 'move'.

Willy.

"SB" <st********@yahoo.com> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
What is the best way to prevent an object from being moved by the garbage
collector (for the lifetime of an application)? Pinning seems to be
designed for temporary operations...so I guess that's not an option.

The reason I'm ask is because I have a class that contains many delegates
that are used as callback functions to a C dll. The dll may call any one
of these delegates at any time...so their addresses must be set in stone
until the app is closed.

I believe I can allocate the object on the stack to prevent it from being
affected by the garbage collector..but I'm not sure if that will work or
how to go about doing it.

Any info would be appreciated!

TIA,
sb


Nov 16 '05 #3

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

Similar topics

18
by: Rein Petersen | last post by:
Is there any way to adjust thread priority for the garbage collector? Would be nice if I could tune the thread priority rules for the garbage collector too... From my readings of the process,...
11
by: Fabien Penso | last post by:
Hi. I am trying to make this work but I got a weird behavior. I got a very basic system, I call a unmanaged "dllimported" function and give it a structure of callback functions. Sometimes,...
18
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful...
4
by: R. MacDonald | last post by:
Hello, all, I have a .NET application (VB) that passes the address of a delegate to unmanaged code in a DLL. The unmanaged code then uses the delegate as a call-back. This seems to work...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
8
by: Paul.Lee.1971 | last post by:
Hi everyone, A program that I'm helping to code seems to slow down drastically during initialisation, and looking at the profiling graph, it seems to be the garbage collector thats slowing things...
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 =...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.