本文整理汇总了C#中System.Runtime.InteropServices.GCHandle.AddrOfPinnedObject方法的典型用法代码示例。如果您正苦于以下问题:C# GCHandle.AddrOfPinnedObject方法的具体用法?C# GCHandle.AddrOfPinnedObject怎么用?C# GCHandle.AddrOfPinnedObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.GCHandle
的用法示例。
在下文中一共展示了GCHandle.AddrOfPinnedObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FFTWtest
// Initializes FFTW and all arrays
// n: Logical size of the transform
public FFTWtest(int n)
{
System.Console.WriteLine("Starting test with n = " + n + " complex numbers");
fftLength = n;
// create two unmanaged arrays, properly aligned
pin = fftwf.malloc(n * 8);
pout = fftwf.malloc(n * 8);
// create two managed arrays, possibly misalinged
// n*2 because we are dealing with complex numbers
fin = new float[n * 2];
fout = new float[n * 2];
// and two more for double FFTW
din = new double[n * 2];
dout = new double[n * 2];
// get handles and pin arrays so the GC doesn't move them
hin = GCHandle.Alloc(fin, GCHandleType.Pinned);
hout = GCHandle.Alloc(fout, GCHandleType.Pinned);
hdin = GCHandle.Alloc(din, GCHandleType.Pinned);
hdout = GCHandle.Alloc(dout, GCHandleType.Pinned);
// create a few test transforms
fplan1 = fftwf.dft_1d(n, pin, pout, fftw_direction.Forward, fftw_flags.Estimate);
fplan2 = fftwf.dft_1d(n, hin.AddrOfPinnedObject(), hout.AddrOfPinnedObject(),
fftw_direction.Forward, fftw_flags.Estimate);
fplan3 = fftwf.dft_1d(n, hout.AddrOfPinnedObject(), pin,
fftw_direction.Backward, fftw_flags.Measure);
// end with transforming back to original array
fplan4 = fftwf.dft_1d(n, hout.AddrOfPinnedObject(), hin.AddrOfPinnedObject(),
fftw_direction.Backward, fftw_flags.Estimate);
// and check a quick one with doubles, just to be sure
fplan5 = fftw.dft_1d(n, hdin.AddrOfPinnedObject(), hdout.AddrOfPinnedObject(),
fftw_direction.Backward, fftw_flags.Measure);
// create a managed plan as well
min = new fftw_complexarray(din);
mout = new fftw_complexarray(dout);
mplan = fftw_plan.dft_1d(n, min, mout, fftw_direction.Forward, fftw_flags.Estimate);
// fill our arrays with an arbitrary complex sawtooth-like signal
for (int i = 0; i < n * 2; i++)
fin[i] = i % 50;
for (int i = 0; i < n * 2; i++)
fout[i] = i % 50;
for (int i = 0; i < n * 2; i++)
din[i] = i % 50;
// copy managed arrays to unmanaged arrays
Marshal.Copy(fin, 0, pin, n * 2);
Marshal.Copy(fout, 0, pout, n * 2);
}
示例2: Invoke
private int Invoke(SOCKET socket)
{
_recvOverlapped.hEvent = SocketImports.WSACreateEvent();
if (_recvOverlapped.hEvent == IntPtr.Zero)
{
// dead, close socket?
return -1;
}
_gcWSABuffer = GCHandle.Alloc(_WSABuffer, GCHandleType.Pinned);
var lpWSABuffer = (WSABuffer*)_gcWSABuffer.AddrOfPinnedObject();
_gcRecvOverlapped = GCHandle.Alloc(_recvOverlapped, GCHandleType.Pinned);
var plRecvOverlapped = (WSAOverlapped*)_gcRecvOverlapped.AddrOfPinnedObject();
int rc = SocketImports.WSARecv(socket, lpWSABuffer, 1, out _bytesTransferred, ref _socketFlags, plRecvOverlapped, IntPtr.Zero);
_gcWSABuffer.Free();
_gcRecvOverlapped.Free();
if (rc == SocketImports.SOCKET_ERROR)
{
int err = SocketImports.WSAGetLastError();
if (SocketImports.WSA_IO_PENDING != err)
{
Console.WriteLine("WSARecv failed with error: {0}/{1}", rc, err);
}
}
return rc;
}
示例3: 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;
}
示例4: 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();
}
}
示例5: CommitToSolver
public override void CommitToSolver()
{
if (skinIndices != null && skinPoints != null && skinNormals != null && skinRadiiBackstops != null && skinStiffnesses != null){
Oni.UnpinMemory(skinIndicesHandle);
Oni.UnpinMemory(skinPointsHandle);
Oni.UnpinMemory(skinNormalsHandle);
Oni.UnpinMemory(skinRadiiBackstopsHandle);
Oni.UnpinMemory(skinStiffnessesHandle);
skinIndicesHandle = Oni.PinMemory(skinIndices);
skinPointsHandle = Oni.PinMemory(skinPoints);
skinNormalsHandle = Oni.PinMemory(skinNormals);
skinRadiiBackstopsHandle = Oni.PinMemory(skinRadiiBackstops);
skinStiffnessesHandle = Oni.PinMemory(skinStiffnesses);
Oni.SetSkinConstraints(solver.Solver,
skinIndicesHandle.AddrOfPinnedObject(),
skinPointsHandle.AddrOfPinnedObject(),
skinNormalsHandle.AddrOfPinnedObject(),
skinRadiiBackstopsHandle.AddrOfPinnedObject(),
skinStiffnessesHandle.AddrOfPinnedObject());
CommitActive();
}
}
示例6: ColorCodec
public ColorCodec(RGBAPixel[] pixels)
{
_srcCount = pixels.Length;
_handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
_pData = (RGBAPixel*)_handle.AddrOfPinnedObject();
Evaluate();
}
示例7: Execute
public void Execute()
{
// Create GS Instance (GS-API)
gsapi_new_instance(out _gsInstancePtr, IntPtr.Zero);
// Build Argument Arrays
_gsArgStrHandles = new GCHandle[_gsParams.Count];
_gsArgPtrs = new IntPtr[_gsParams.Count];
// Populate Argument Arrays
for (int i = 0; i < _gsParams.Count; i++)
{
_gsArgStrHandles[i] = GCHandle.Alloc(System.Text.ASCIIEncoding.ASCII.GetBytes(_gsParams[i].ToString()), GCHandleType.Pinned);
_gsArgPtrs[i] = _gsArgStrHandles[i].AddrOfPinnedObject();
}
// Allocate memory that is protected from Garbage Collection
_gsArgPtrsHandle = GCHandle.Alloc(_gsArgPtrs, GCHandleType.Pinned);
// Init args with GS instance (GS-API)
gsapi_init_with_args(_gsInstancePtr, _gsArgStrHandles.Length, _gsArgPtrsHandle.AddrOfPinnedObject());
// Free unmanaged memory
for (int i = 0; i < _gsArgStrHandles.Length; i++)
_gsArgStrHandles[i].Free();
_gsArgPtrsHandle.Free();
// Exit the api (GS-API)
gsapi_exit(_gsInstancePtr);
// Delete GS Instance (GS-API)
gsapi_delete_instance(_gsInstancePtr);
}
示例8: AdaptAudioDataImpl
private unsafe void AdaptAudioDataImpl()
{
var isStereo = WaveFormat.Channels == 2;
// allocate the new audio buffer
var sampleRateRatio = Math.Min(1, WaveFormat.SampleRate / (float)SoundEffectInstance.SoundEffectInstanceFrameRate); // we don't down-sample in current version
var newWaveDataSize = (int)Math.Floor(WaveDataSize / sampleRateRatio) * (isStereo ? 1 : 2);
WaveDataArray = new byte[newWaveDataSize];
fixed (byte* pNewWaveData = WaveDataArray)
{
// re-sample the audio data
if (Math.Abs(sampleRateRatio - 1f) < MathUtil.ZeroTolerance && !isStereo)
DuplicateTracks(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize);
else if (Math.Abs(sampleRateRatio - 0.5f) < MathUtil.ZeroTolerance)
UpSampleByTwo(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize, WaveFormat.Channels, !isStereo);
else
UpSample(WaveDataPtr, (IntPtr)pNewWaveData, newWaveDataSize, sampleRateRatio, WaveFormat.Channels, !isStereo);
}
// update the wave data buffer
pinnedWaveData = GCHandle.Alloc(WaveDataArray, GCHandleType.Pinned);
WaveDataPtr = pinnedWaveData.AddrOfPinnedObject();
WaveDataSize = newWaveDataSize;
// Free unused anymore C# data buffer
Utilities.FreeMemory(nativeDataBuffer);
nativeDataBuffer = IntPtr.Zero;
}
示例9: AVPacket
public AVPacket()
{
AutoGen.AVPacket packet = new AutoGen.AVPacket();
_handle = GCHandle.Alloc(packet, GCHandleType.Pinned);
_packet = (AutoGen.AVPacket*)_handle.AddrOfPinnedObject().ToPointer();
}
示例10: AllocateData
private IntPtr AllocateData(CvEnum.DepthType type, int channels, int totalInBytes)
{
FreeData();
switch (type)
{
//case CvEnum.DepthType.Cv8U:
// _data = new byte[totalInBytes];
// break;
case CvEnum.DepthType.Cv8S:
_data = new SByte[totalInBytes];
break;
case CvEnum.DepthType.Cv16U:
_data = new UInt16[totalInBytes >> 1];
break;
case CvEnum.DepthType.Cv16S:
_data = new Int16[totalInBytes >> 1];
break;
case CvEnum.DepthType.Cv32S:
_data = new Int32[totalInBytes >> 2];
break;
case CvEnum.DepthType.Cv32F:
_data = new float[totalInBytes >> 2];
break;
case CvEnum.DepthType.Cv64F:
_data = new double[totalInBytes >> 3];
break;
default:
_data = new byte[totalInBytes];
break;
}
_dataHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
return _dataHandle.AddrOfPinnedObject();
}
示例11: Initialize
protected override void Initialize()
{
optionsgchandle = GCHandle.Alloc(options, GCHandleType.Pinned);
opaque = optionsgchandle.AddrOfPinnedObject();
hoedown_html_toc_renderer_new(ref callbacks, opaque, 0);
base.Initialize();
}
示例12: DecomposedResult
public unsafe DecomposedResult(int maxInstructions)
{
MaxInstructions = maxInstructions;
_instMem = new byte[maxInstructions * sizeof(DecomposedInstructionStruct)];
_gch = GCHandle.Alloc(_instMem, GCHandleType.Pinned);
_instructionsPointer = (DecomposedInstructionStruct *)_gch.AddrOfPinnedObject();
}
示例13: MarshalMultipleValueStructure
public MarshalMultipleValueStructure(byte[] key, byte[][] values)
{
if (values == null)
throw new ArgumentNullException(nameof(values));
_size = GetSize(values);
_count = GetCount(values);
_flattened = values.SelectMany(x => x).ToArray();
_valuesHandle = GCHandle.Alloc(_flattened, GCHandleType.Pinned);
_key = key;
_keyHandle = GCHandle.Alloc(_key, GCHandleType.Pinned);
Values = new[]
{
new ValueStructure
{
size = new IntPtr(_size),
data = _valuesHandle.AddrOfPinnedObject()
},
new ValueStructure
{
size = new IntPtr(_count)
}
};
Key = new ValueStructure
{
size = new IntPtr(_key.Length),
data = _keyHandle.AddrOfPinnedObject()
};
}
示例14: FpuRegisters
public FpuRegisters()
{
m_Regs = new ulong[32];
m_RegHandle = GCHandle.Alloc(m_Regs, GCHandleType.Pinned);
m_RegsPtr = m_RegHandle.AddrOfPinnedObject();
/* TODO: Free handle on dispose */
}
示例15: MemoryPoolSlab
public MemoryPoolSlab(byte[] data)
{
_data = data;
_gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
_nativePointer = _gcHandle.AddrOfPinnedObject();
_isActive = true;
}