本文整理汇总了C#中Vector.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Dispose方法的具体用法?C# Vector.Dispose怎么用?C# Vector.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PositivePartMean
unsafe double PositivePartMean(Vector input)
{
int n = input.Length;
double* buffer = input.Buffer;
double sum = 0;
for (int z = 0; z < n; z++)
if (buffer[z] > 0) sum += buffer[z];
GC.KeepAlive(input);// if input is the result of a temporay op.
input.Dispose();
return sum / n;
}
示例2: SmoothedPositivePartMean
unsafe double SmoothedPositivePartMean(Vector input)
{
double scaling = Math.Min(1, s0 / 2000);
int n = input.Length;
double* buffer = input.Buffer;
double sum = 0;
for (int z = 0; z < n; z++)
if (buffer[z] > scaling) sum += buffer[z];
else
if (buffer[z] > -15)
sum += scaling*Math.Exp(buffer[z]-scaling);
GC.KeepAlive(input);// if input is the result of a temporay op.
input.Dispose();
return sum / n;
}
示例3: Main
public static void Main()
{
Console.WriteLine( "Creating some objects:" );
Vector a = new Vector(3,4,5);
Vector b = new Vector(10,11,12);
Console.WriteLine( " Created " + a.print() );
Console.WriteLine( " Created " + b.print() );
// ----- Call an overloaded operator -----
// This calls the wrapper we placed around
//
// operator+(const Vector &a, const Vector &)
//
// It returns a new allocated object.
Console.WriteLine( "Adding a+b" );
Vector c = example.addv(a,b);
Console.WriteLine( " a+b = " + c.print() );
// Note: Unless we free the result, a memory leak will occur if the -noproxy commandline
// is used as the proxy classes define finalizers which call the Dispose() method. When
// -noproxy is not specified the memory management is controlled by the garbage collector.
// You can still call Dispose(). It will free the c++ memory immediately, but not the
// C# memory! You then must be careful not to call any member functions as it will
// use a NULL c pointer on the underlying c++ object. We set the C# object to null
// which will then throw a C# exception should we attempt to use it again.
c.Dispose();
c = null;
// ----- Create a vector array -----
Console.WriteLine( "Creating an array of vectors" );
VectorArray va = new VectorArray(10);
Console.WriteLine( " va = " + va.ToString() );
// ----- Set some values in the array -----
// These operators copy the value of Vector a and Vector b to the vector array
va.set(0,a);
va.set(1,b);
// This works, but it would cause a memory leak if -noproxy was used!
va.set(2,example.addv(a,b));
// Get some values from the array
Console.WriteLine( "Getting some array values" );
for (int i=0; i<5; i++)
Console.WriteLine( " va(" + i + ") = " + va.get(i).print() );
// Watch under resource meter to check on this
Console.WriteLine( "Making sure we don't leak memory." );
for (int i=0; i<1000000; i++)
c = va.get(i%10);
// ----- Clean up -----
// This could be omitted. The garbage collector would then clean up for us.
Console.WriteLine( "Cleaning up" );
va.Dispose();
a.Dispose();
b.Dispose();
}