本文整理汇总了C#中GCHandle类的典型用法代码示例。如果您正苦于以下问题:C# GCHandle类的具体用法?C# GCHandle怎么用?C# GCHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GCHandle类属于命名空间,在下文中一共展示了GCHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFirstBridge
static void CreateFirstBridge () {
Bridge b = new Bridge() {
__test = 0,
id = "first",
};
weak_track_handle = GCHandle.Alloc (b, GCHandleType.WeakTrackResurrection);
}
示例2: CreateSecondBridge
static void CreateSecondBridge () {
Bridge b = new Bridge() {
__test = 1,
id = "second",
};
weak_track_handle2 = GCHandle.Alloc (b, GCHandleType.WeakTrackResurrection);
}
示例3: Update
void Update()
{
if (state == 0) {
AndroidJavaClass UnityOpenCVLoaderJava = new AndroidJavaClass(UNITY_OPENCV_LOADER);
var b = UnityOpenCVLoaderJava.CallStatic<Boolean>("isSuccess");
if (b) {
state = 1;
}
} else if (state == 1) {
if (cameraInstance == IntPtr.Zero) cameraInstance = CreateCameraInstance ();
if (Open (cameraInstance, 0, width, height)) {
texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
pixels = texture.GetPixels32 ();
pixelsHandle = GCHandle.Alloc (pixels, GCHandleType.Pinned);
pixelsPtr = pixelsHandle.AddrOfPinnedObject ();
GetComponent<Renderer>().material.mainTexture = texture;
state = 2;
} else {
state = -1;
}
} else if (state == 2) {
getCameraTexture (cameraInstance, pixelsPtr, width, height);
texture.SetPixels32 (pixels);
texture.Apply ();
}
}
示例4: Update
// Update is called once per frame
void Update()
{
// off-screen rendering
var camtex = RenderTexture.GetTemporary (camWidth, camHeight, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 1);
myCamera.targetTexture = camtex;
myCamera.Render ();
RenderTexture.active = camtex;
tex.ReadPixels (new Rect (0, 0, camtex.width, camtex.height), 0, 0);
tex.Apply ();
// Convert texture to ptr
texturePixels_ = tex.GetPixels32();
texturePixelsHandle_ = GCHandle.Alloc(texturePixels_, GCHandleType.Pinned);
texturePixelsPtr_ = texturePixelsHandle_.AddrOfPinnedObject();
// Show a window
fullWindow (windowName, displayNum, texturePixelsPtr_, camWidth, camHeight);
texturePixelsHandle_.Free();
RenderTexture.active = null;
RenderTexture.ReleaseTemporary (camtex);
myCamera.targetTexture = null;
}
示例5: DoLoadBank
private static AKRESULT DoLoadBank(string in_bankPath)
{
ms_www = new WWW(in_bankPath);
while( ! ms_www.isDone )
{
#if ! UNITY_METRO
System.Threading.Thread.Sleep(WaitMs);
#endif // #if ! UNITY_METRO
}
uint in_uInMemoryBankSize = 0;
try
{
ms_pinnedArray = GCHandle.Alloc(ms_www.bytes, GCHandleType.Pinned);
ms_pInMemoryBankPtr = ms_pinnedArray.AddrOfPinnedObject();
in_uInMemoryBankSize = (uint)ms_www.bytes.Length;
}
catch
{
return AKRESULT.AK_Fail;
}
AKRESULT result = AkSoundEngine.LoadBank(ms_pInMemoryBankPtr, in_uInMemoryBankSize, out ms_bankID);
return result;
}
示例6: CreateBuffer
private void CreateBuffer(int width, int height)
{
// Free buffer if it's too small
if (_frameHandle.IsAllocated && _frameData != null)
{
if (_frameData.Length < _frameWidth * _frameHeight)
{
FreeBuffer();
}
}
if (_frameData == null)
{
_frameWidth = width;
_frameHeight = height;
_frameData = new Color32[_frameWidth * _frameHeight];
_frameHandle = GCHandle.Alloc(_frameData, GCHandleType.Pinned);
_framePointer = _frameHandle.AddrOfPinnedObject();
#if TEXTURETEST
_testTexture = new Texture2D(_frameWidth ,_frameHeight, TextureFormat.ARGB32, false, false);
_testTexture.Apply(false, false);
#endif
}
}
示例7: Main
public static int Main()
{
int[] arr = new int[1000];
GCHandle[] arrhandle = new GCHandle[10000]; // array of handles to the same object
IntPtr[] oldaddress = new IntPtr[10000]; // store old addresses
IntPtr[] newaddress = new IntPtr[10000]; // store new addresses
for (int i = 0; i < 10000; i++)
{
arrhandle[i] = GCUtil.Alloc(arr, GCHandleType.Pinned);
oldaddress[i] = GCUtil.AddrOfPinnedObject(arrhandle[i]);
}
GC.Collect();
GC.WaitForPendingFinalizers();
for (int i = 0; i < 10000; i++)
{
newaddress[i] = GCUtil.AddrOfPinnedObject(arrhandle[i]);
}
for (int i = 0; i < 10000; i++)
{
if (oldaddress[i] != newaddress[i])
{
Console.WriteLine("Test failed");
return 1;
}
}
Console.WriteLine("Test passed");
return 100;
}
示例8: CreateObj
public CreateObj()
{
obj = new Dummy();
Console.WriteLine("Allocating a Weak handle to object..");
handle = GCHandle.Alloc(obj, GCHandleType.Weak);
// making a copy of the handle
copy = handle;
}
示例9: RegisterCommandCallback
public static void RegisterCommandCallback(CommandCallbackDelegate fun)
{
_gcHandle = GCHandle.Alloc(fun);
if (IntPtr.Size == 8)
RegisterCommandCallback_x64(fun);
else
RegisterCommandCallback_x86(fun);
}
示例10: Matrix
public Matrix(int size)
{
if (!_validSizes.Contains(size)) throw new ArgumentOutOfRangeException("size");
_size = size;
_data = new int[size * size];
_dataPtrHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
_dataPtr = (int*)_dataPtrHandle.AddrOfPinnedObject().ToPointer();
}
示例11: Start
// Use this for initialization
void Start () {
camera_ = getCamera(device);
setCameraProp(camera_, width, height, fps);
texture_ = new Texture2D(width, height, TextureFormat.ARGB32, false);
pixels_ = texture_.GetPixels32();
pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
pixels_ptr_ = pixels_handle_.AddrOfPinnedObject();
GetComponent<Renderer>().material.mainTexture = texture_;
}
示例12: alloc_many
static void alloc_many()
{
int
small_count
=
count
/
2;
GCHandle[]
more
=
new
GCHandle
[small_count];
int
i;
for
(i
=
0;
i
<
small_count;
++i)
{
GCHandleType
t
=
(GCHandleType)
(i
&
3);
more
[i]
=
GCHandle.Alloc
(i,
t);
}
for
(i
=
0;
i
<
small_count;
++i)
{
more
[i].Free
();
}
Console.WriteLine
("alloc many: {0}",
small_count);
}
示例13: Cleanup
private void Cleanup(GCHandle[] argStrHandles, GCHandle argPtrsHandle,
IntPtr gsInstancePtr)
{
for (int i = 0; i < argStrHandles.Length; i++)
argStrHandles[i].Free();
argPtrsHandle.Free();
ExitAPI(gsInstancePtr);
DeleteAPIInstance(gsInstancePtr);
}
示例14: GetContextHandle
public IntPtr GetContextHandle()
{
if ((_selfGCHandle.IsAllocated == false))
{
_selfGCHandle = GCHandle.Alloc(
this,
GCHandleType.Normal);
}
return GCHandle.ToIntPtr(_selfGCHandle);
}
示例15: deterministicStaticInit
private static void deterministicStaticInit()
{
__noData = (IntPtr) (-1);
__defaultCmdSpace = (IntPtr) (-1);
modFlags = ApiGroup.Off;
modIdentity = string.Empty;
ctrlCallback = new CtrlCB(Bid.SetApiGroupBits);
cookieObject = new BindingCookie();
hCookie = GCHandle.Alloc(cookieObject, GCHandleType.Pinned);
}