本文整理汇总了C#中System.Runtime.InteropServices.GCHandle类的典型用法代码示例。如果您正苦于以下问题:C# GCHandle类的具体用法?C# GCHandle怎么用?C# GCHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GCHandle类属于System.Runtime.InteropServices命名空间,在下文中一共展示了GCHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FreeString
public static void FreeString(ref GCHandle handle)
{
if (handle == NullHandle)
return;
handle.Free();
}
示例2: LoadFromMemory
public unsafe static Image LoadFromMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle)
{
using (var memoryStream = new UnmanagedMemoryStream((byte*)pSource, size))
using (var bitmap = (Bitmap)BitmapFactory.DecodeStream(memoryStream))
{
var bitmapData = bitmap.LockPixels();
var image = Image.New2D(bitmap.Width, bitmap.Height, 1, PixelFormat.B8G8R8A8_UNorm, 1, bitmap.RowBytes);
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
// Directly load image as RGBA instead of BGRA, because OpenGL ES devices don't support it out of the box (extension).
CopyMemoryBGRA(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
#else
Utilities.CopyMemory(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
#endif
bitmap.UnlockPixels();
if (handle != null)
handle.Value.Free();
else if (!makeACopy)
Utilities.FreeMemory(pSource);
return image;
}
}
示例3: IntegralImage2
/// <summary>
/// Constructs a new Integral image of the given size.
/// </summary>
///
protected IntegralImage2(int width, int height, bool computeTilted)
{
this.width = width;
this.height = height;
this.nWidth = width + 1;
this.nHeight = height + 1;
this.tWidth = width + 2;
this.tHeight = height + 2;
this.nSumImage = new int[nHeight, nWidth];
this.nSumHandle = GCHandle.Alloc(nSumImage, GCHandleType.Pinned);
this.nSum = (int*)nSumHandle.AddrOfPinnedObject().ToPointer();
this.sSumImage = new int[nHeight, nWidth];
this.sSumHandle = GCHandle.Alloc(sSumImage, GCHandleType.Pinned);
this.sSum = (int*)sSumHandle.AddrOfPinnedObject().ToPointer();
if (computeTilted)
{
this.tSumImage = new int[tHeight, tWidth];
this.tSumHandle = GCHandle.Alloc(tSumImage, GCHandleType.Pinned);
this.tSum = (int*)tSumHandle.AddrOfPinnedObject().ToPointer();
}
}
示例4: DecomposedResult
public unsafe DecomposedResult(int maxInstructions)
{
MaxInstructions = maxInstructions;
_instMem = new byte[maxInstructions * sizeof(DecomposedInstructionStruct)];
_gch = GCHandle.Alloc(_instMem, GCHandleType.Pinned);
_instructionsPointer = (DecomposedInstructionStruct *)_gch.AddrOfPinnedObject();
}
示例5: SQLite3
internal SQLite3(SQLiteDateFormats fmt)
: base(fmt)
{
#if MONOTOUCH
gch = GCHandle.Alloc (this);
#endif
}
示例6: TtsBufferManaged
public TtsBufferManaged()
{
_value = new TTS_BUFFER_T();
_pinHandle = GCHandle.Alloc(this, GCHandleType.Pinned);
_value.MaxBufferLength = TTS_BUFFER_T.BufferSize;
_value.DataPtr = Marshal.AllocHGlobal(TTS_BUFFER_T.BufferSize);
}
示例7: LoadFromMemory
public static unsafe Image LoadFromMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle)
{
var stream = new BinarySerializationReader(new NativeMemoryStream((byte*)pSource, size));
// Read and check magic code
var magicCode = stream.ReadUInt32();
if (magicCode != MagicCode)
return null;
// Read header
var imageDescription = new ImageDescription();
imageDescriptionSerializer.Serialize(ref imageDescription, ArchiveMode.Deserialize, stream);
if (makeACopy)
{
var buffer = Utilities.AllocateMemory(size);
Utilities.CopyMemory(buffer, pSource, size);
pSource = buffer;
makeACopy = false;
}
var image = new Image(imageDescription, pSource, 0, handle, !makeACopy);
var totalSizeInBytes = stream.ReadInt32();
if (totalSizeInBytes != image.TotalSizeInBytes)
throw new InvalidOperationException("Image size is different than expected.");
// Read image data
stream.Serialize(image.DataPointer, image.TotalSizeInBytes);
return image;
}
示例8: Unpin
public void Unpin()
{
if (_operationHandle.IsAllocated)
{
Debug.Assert(_handlesOpenWithCallback == 0);
// This method only gets called when the WinHTTP request/websocket handles are fully closed and thus
// all async operations are done. So, it is safe at this point to unpin the buffers and release
// the strong GCHandle for this object.
if (_cachedReceivePinnedBuffer.IsAllocated)
{
_cachedReceivePinnedBuffer.Free();
_cachedReceivePinnedBuffer = default(GCHandle);
}
if (_cachedSendPinnedBuffer.IsAllocated)
{
_cachedSendPinnedBuffer.Free();
_cachedSendPinnedBuffer = default(GCHandle);
}
_operationHandle.Free();
_operationHandle = default(GCHandle);
}
}
示例9: BufferData
public static VBO<Vector3> BufferData(VBO<Vector3> vbo, Vector3[] data, GCHandle handle)
{
if (vbo == null) return new VBO<Vector3>(data, BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);
vbo.BufferSubDataPinned(BufferTarget.ArrayBuffer, 12 * data.Length, handle.AddrOfPinnedObject());
return vbo;
}
示例10: Draw3DPlotLeft
public static void Draw3DPlotLeft(float[] data, float depth, Vector3 color, Matrix4 viewMatrix, bool log = false)
{
if (data.Length < 441) throw new ArgumentException("The argument data was not the correct length.");
for (int i = 0; i < fftData.Length; i++)
fftData[i] = new Vector3((log ? Math.Log10(i) * 166 : i) - 441 / 2f, Math.Max(-200, Math.Min(200, 200 * data[i])), depth);
//fftData[i] = new Vector3(i - 441 / 2f, Math.Max(-200, Math.Min(200, 200 * data[i])), depth);
if (fftVAO == null)
{
int[] array = new int[441];
for (int i = 0; i < array.Length; i++) array[i] = i;
fftHandle = GCHandle.Alloc(fftData, GCHandleType.Pinned);
fftVBO = BufferData(fftVBO, fftData, fftHandle);
fftVAO = new VAO<Vector3>(Shaders.SimpleColoredShader, fftVBO, "in_position", new VBO<int>(array, BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticDraw));
fftVAO.DrawMode = BeginMode.LineStrip;
}
else fftVBO = BufferData(fftVBO, fftData, fftHandle);
Shaders.SimpleColoredShader.Use();
Shaders.SimpleColoredShader["projectionMatrix"].SetValue(Program.uiProjectionMatrix);
Shaders.SimpleColoredShader["viewMatrix"].SetValue(viewMatrix);
Shaders.SimpleColoredShader["modelMatrix"].SetValue(Matrix4.CreateTranslation(new Vector3(72 + 441 / 2f, 288, 0)));
Shaders.SimpleColoredShader["color"].SetValue(color);
fftVAO.Draw();
}
示例11: WaveRecorder
public WaveRecorder(int deviceIndex, double sampleRate, int framesPerBuffer, AudioBufferAvailableDelegate bufferAvailable)
{
this._bufferAvailable = bufferAvailable;
PaStreamParameters inputParameters = new PaStreamParameters();
inputParameters.device = deviceIndex;
inputParameters.channelCount = 2;
inputParameters.suggestedLatency = 0.0;
inputParameters.sampleFormat = PaSampleFormat.PaFloat32;
PaError paError1 = PortAudioAPI.Pa_IsFormatSupported(ref inputParameters, IntPtr.Zero, sampleRate);
if (paError1 != PaError.paNoError)
throw new ApplicationException(paError1.ToString());
this._gcHandle = GCHandle.Alloc((object) this);
PaError paError2 = PortAudioAPI.Pa_OpenStream(out this._streamHandle, ref inputParameters, IntPtr.Zero, sampleRate, (uint) framesPerBuffer, PaStreamFlags.PaNoFlag, this._paCallback, (IntPtr) this._gcHandle);
if (paError2 != PaError.paNoError)
{
this._gcHandle.Free();
throw new ApplicationException(paError2.ToString());
}
PaError paError3 = PortAudioAPI.Pa_StartStream(this._streamHandle);
if (paError3 != PaError.paNoError)
{
int num = (int) PortAudioAPI.Pa_CloseStream(this._streamHandle);
this._gcHandle.Free();
throw new ApplicationException(paError3.ToString());
}
}
示例12: Main
static void Main(string[] args)
{
Console.Write("Enter Passphrase: ");
using (var passphrase = GetPassphraseFromConsole())
{
Console.WriteLine("Your password:");
RuntimeHelpers.PrepareConstrainedRegions();
unsafe
{
var arPass = new char[passphrase.Length];
var handle = new GCHandle();
System.IntPtr ptr = System.IntPtr.Zero;
ptr = Marshal.SecureStringToBSTR(passphrase);
char* ptrPassword = (char*)ptr;
RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
(uData) =>
{
handle = GCHandle.Alloc(arPass, System.Runtime.InteropServices.GCHandleType.Pinned);
ptrPassword = (char*)ptr;
char* ptrArPass = (char*)handle.AddrOfPinnedObject();
for (var ii = 0; ii < arPass.Length; ii++)
{
ptrArPass[ii] = ptrPassword[ii];
}
Console.WriteLine(arPass);
},
(uData, exceptionThrown) =>
{
if (exceptionThrown)
{
Console.WriteLine("Exception thrown.");
}
Marshal.ZeroFreeBSTR(ptr);
for (var ii = 0; ii < arPass.Length; ii++)
{
arPass[ii] = '\0';
}
handle.Free();
},
null
);
}
}
}
示例13: PSP
public PSP(CoreComm comm, string isopath)
{
ServiceProvider = new BasicServiceProvider(this);
if (attachedcore != null)
{
attachedcore.Dispose();
attachedcore = null;
}
CoreComm = comm;
logcallback = new PPSSPPDll.LogCB(LogCallbackFunc);
bool good = PPSSPPDll.init(isopath, logcallback);
LogFlush();
if (!good)
throw new Exception("PPSSPP Init failed!");
vidhandle = GCHandle.Alloc(screenbuffer, GCHandleType.Pinned);
PPSSPPDll.setvidbuff(vidhandle.AddrOfPinnedObject());
CoreComm.VsyncDen = 1;
CoreComm.VsyncNum = 60;
CoreComm.RomStatusDetails = "It puts the scythe in the chicken or it gets the abyss again!";
attachedcore = this;
}
示例14: DvProviderUpnpOrgSwitchPower1
/// <summary>
/// Constructor
/// </summary>
/// <param name="aDevice">Device which owns this provider</param>
protected DvProviderUpnpOrgSwitchPower1(DvDevice aDevice)
: base(aDevice, "upnp.org", "SwitchPower", 1)
{
iGch = GCHandle.Alloc(this);
iPropertyStatus = new PropertyBool(new ParameterBool("Status"));
AddProperty(iPropertyStatus);
}
示例15: ReadStart
public void ReadStart(
Func<UvStreamHandle, int, object, Libuv.uv_buf_t> allocCallback,
Action<UvStreamHandle, int, Exception, object> readCallback,
object state)
{
if (_readVitality.IsAllocated)
{
throw new InvalidOperationException("TODO: ReadStop must be called before ReadStart may be called again");
}
try
{
_allocCallback = allocCallback;
_readCallback = readCallback;
_readState = state;
_readVitality = GCHandle.Alloc(this, GCHandleType.Normal);
_uv.read_start(this, _uv_alloc_cb, _uv_read_cb);
}
catch
{
_allocCallback = null;
_readCallback = null;
_readState = null;
if (_readVitality.IsAllocated)
{
_readVitality.Free();
}
throw;
}
}