我想在垃圾收集类中保留一个静态计数器,并使用Interlocked :: Increment将其增加。 什么是C ++ / CLI语法来做到这一点?
我一直在尝试以下方面的变化,但迄今为止没有运气:
ref class Foo { static __int64 _counter; __int64 Next() { return System::Threading::Interlocked::Increment( &_counter ); } };I would like to keep a static counter in a garbage collected class and increment it using Interlocked::Increment. What's the C++/CLI syntax to do this?
I've been trying variations on the following, but no luck so far:
ref class Foo { static __int64 _counter; __int64 Next() { return System::Threading::Interlocked::Increment( &_counter ); } };最满意答案
您需要使用%跟踪引用符号对_int64值使用跟踪引用:
ref class Bar { static __int64 _counter; __int64 Next() { __int64 %trackRefCounter = _counter; return System::Threading::Interlocked::Increment(trackRefCounter); } };You need to use a tracking reference to your _int64 value, using the % tracking reference notation:
ref class Bar { static __int64 _counter; __int64 Next() { __int64 %trackRefCounter = _counter; return System::Threading::Interlocked::Increment(trackRefCounter); } };如何使用System :: Threading :: Interlocked :: Increment对来自C ++ / CLI的静态变量?(How to use System::Threading::Interlocked::Increment on a static variable from C++/CLI?)我想在垃圾收集类中保留一个静态计数器,并使用Interlocked :: Increment将其增加。 什么是C ++ / CLI语法来做到这一点?
我一直在尝试以下方面的变化,但迄今为止没有运气:
ref class Foo { static __int64 _counter; __int64 Next() { return System::Threading::Interlocked::Increment( &_counter ); } };I would like to keep a static counter in a garbage collected class and increment it using Interlocked::Increment. What's the C++/CLI syntax to do this?
I've been trying variations on the following, but no luck so far:
ref class Foo { static __int64 _counter; __int64 Next() { return System::Threading::Interlocked::Increment( &_counter ); } };最满意答案
您需要使用%跟踪引用符号对_int64值使用跟踪引用:
ref class Bar { static __int64 _counter; __int64 Next() { __int64 %trackRefCounter = _counter; return System::Threading::Interlocked::Increment(trackRefCounter); } };You need to use a tracking reference to your _int64 value, using the % tracking reference notation:
ref class Bar { static __int64 _counter; __int64 Next() { __int64 %trackRefCounter = _counter; return System::Threading::Interlocked::Increment(trackRefCounter); } };
发布评论