作者:GAO-XIANG
转自:http://blog.youkuaiyun.com/xiang__jiangsu/article/details/8119297
本次主要简单介绍AForge.NET中的 AForge命名空间。
AForge:
AForge是AForge.NET framework的核心命名空间,它也包括很多核心类。
类和结构:
ConnectionLostException:连接丢失的异常。语法:publicConnectionLostException(stringmessage)。
DoublePoint Structure:用以描述双精度(double)类型坐标的结构。语法:publicstructDoublePoint。它包含的方法有: add,divide,multiplysubtract.
实例:// assigning coordinates in the constructor
DoublePoint p1 = new DoublePoint( 10, 20 );
// creating a point and assigning coordinates later
DoublePoint p2;
p2.X = 30;
p2.Y = 40;
// calculating distance between two points
double distance = p1.DistanceTo( p2 );
DoublePoint p1 = new DoublePoint( 10, 20 );
// creating a point and assigning coordinates later
DoublePoint p2;
p2.X = 30;
p2.Y = 40;
// calculating distance between two points
double distance = p1.DistanceTo( p2 );
DoubleRange:用最小以及最大值表示双进度范围。语法:publicDoubleRange(doublemin,doublemax)。它包括IsInside,IsOverlapping两个方法, 用以判断值是否被包含。
实例:// assigning coordinates in the constructor
IntPoint p1 = new IntPoint( 10, 20 );
// creating a point and assigning coordinates later
IntPoint p2;
p2.X = 30;
p2.Y = 40;
// calculating distance between two points
double distance = p1.DistanceTo( p2 );
IntPoint p1 = new IntPoint( 10, 20 );
// creating a point and assigning coordinates later
IntPoint p2;
p2.X = 30;
p2.Y = 40;
// calculating distance between two points
double distance = p1.DistanceTo( p2 );
Parallel:使用for方法进行迭代循环,同时可以返回关联循环的计算机工作进程数目(ThreadsCount)。
实例:Parallel.For( 0, 20, delegate( int i )
// which is equivalent to
// for ( int i = 0; i < 20; i++ )
{
System.Diagnostics.Debug.WriteLine( "Iteration: " + i );
// ...
} );
// which is equivalent to
// for ( int i = 0; i < 20; i++ )
{
System.Diagnostics.Debug.WriteLine( "Iteration: " + i );
// ...
} );
值得说明的是,用Parallel.For进行循环效率比for循环来的更高,以下是两个250*250矩阵相乘计算机计算时间(ms)对比:
SystemTools :提供了系统工具CopyUnmanagedMemory,SetUnmanagedMemory,提出这一工具是由于.net未提供任何一种方式对非托管快进 行复制,它仅仅提供了将非托管内存复制到托管内存的方法。