473,394 Members | 2,100 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.

static msclr::auto_gcroot managed variables and the linker lock error

Hi,

I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.

Feb 12 '07 #1
4 2315

"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
Hi,

I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.
It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.

I think you might be able to work around with a pointer to gcroot and lazy
initialization. And you'll have to explicitly delete the gcroot object to
get cleanup right.

And don't even think of using a native class instance declared as a global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.
Feb 13 '07 #2
On Feb 12, 7:12 pm, "Ben Voigt" <r...@nospam.nospamwrote:
"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@k78g2000cwa.googlegr oups.com...
Hi,
I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.

It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.

I think you might be able to work around with a pointer to gcroot and lazy
initialization. And you'll have to explicitly delete the gcroot object to
get cleanup right.

And don't even think of using a native class instance declared as a global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.
I'm not entirely sure what lazy init is, could you elaborate please?

Feb 13 '07 #3

"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
On Feb 12, 7:12 pm, "Ben Voigt" <r...@nospam.nospamwrote:
>"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@k78g2000cwa.googleg roups.com...
Hi,
I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.

It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.

I think you might be able to work around with a pointer to gcroot and
lazy
initialization. And you'll have to explicitly delete the gcroot object
to
get cleanup right.

And don't even think of using a native class instance declared as a
global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.

I'm not entirely sure what lazy init is, could you elaborate please?
Just that initialization waits until the first time you use it, maybe
involving a check for NULL. Writing an explicit initialization function
called from a managed type initializer (also called static constructor or
..cctor) also works well.
Feb 13 '07 #4
On Feb 13, 11:05 am, "Ben Voigt" <r...@nospam.nospamwrote:
"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.com...


On Feb 12, 7:12 pm, "Ben Voigt" <r...@nospam.nospamwrote:
"DaTurk" <mmagd...@hotmail.comwrote in message
>news:11**********************@k78g2000cwa.googleg roups.com...
Hi,
I've noticed that when trying to create a managed, auto_gcrooted
variable in a antive class, the compiler throws linker exceptions.
While searching some forums I found out that this is a bug? I
couldn't find the work around, just numerous references to the fact
there is one. But apparently there are issues as to how to destroy
said objects. Can anyone shed some more light on this topic for me?
It would be much appreciated.
It's the "loader lock", not "linker lock" that will bite you with static
native variables in mixed assemblies. Essentially, when static variables
are initialized, the managed runtime typically isn't started yet, so you
can't create managed objects. Destruction has the same issues, static
variables last until the very end, when the managed runtime has typically
shutdown.
I think you might be able to work around with a pointer to gcroot and
lazy
initialization. And you'll have to explicitly delete the gcroot object
to
get cleanup right.
And don't even think of using a native class instance declared as a
global
to perform your init and cleanup, that's the same problem all over again,
although the linker probably wouldn't recognize it.
I'm not entirely sure what lazy init is, could you elaborate please?

Just that initialization waits until the first time you use it, maybe
involving a check for NULL. Writing an explicit initialization function
called from a managed type initializer (also called static constructor or
.cctor) also works well.- Hide quoted text -

- Show quoted text -
OK, I understand. But what I don't understand is how this allows me
to use a static, gcrooted, managed variable in native code. I'm not
sure what I'm missing.

Feb 13 '07 #5

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

Similar topics

4
by: memememe | last post by:
in java if I was calling a synchronized block and wanted to sync it even for static blocks of code I could do a synchronize(theObject.getClass()), can I do a lock(theObject.GetType()) on C# and...
3
by: Ant | last post by:
Hi, Can you declare a variable as static in C#? If not, then is there a 'module' level area or eqivelant in C# in which you can do this? Thanks in advance Ant
8
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
5
by: Frank Wisniewski | last post by:
I use static variables in my asp.net apps instead of application variables to store global parameters, its worked well for me so far but I was wondering if it is efficient. Does anyone know how...
3
by: Diebels | last post by:
Hi, I have some problems using static variables which results in a core dump. I have attached code and coredump to the end of my message. I am trying to implement a kind of factory design. I...
7
by: jab3 | last post by:
Does JavaScript have "static" variables. That is, as in C (or local in Perl)? How can I keep a variable in a JavaScript function that doesn't change from call to call? It may not make sense in...
7
by: jois.de.vivre | last post by:
Hi, I'm having some linker issues when using static variables in a class. class TestClass { public: TestClass() { Count++;
1
by: Ian | last post by:
I've just discovered the msclr::lock class in the C++ Support Library online documentation. This seems like a much cleaner way to implement thread protection than using...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.