题
请先查看代码.
这是我的自定义类:
public class float2D
{
public float X { get; private set; }
public float Y { get; private set; }
public float2D(float x, float y)
{
this.X = x;
this.Y = y;
}
public static explicit operator Point(float2D x)
{
return new Point((int)x.X, (int)x.Y);
}
...
}
Run Code Online (Sandbox Code Playgroud)
这是我写的测试代码:
private void TEST()
{
float2D V = new float2D(1, 1);
Point P = Point.Empty;
P = (Point)V; // Works
P = (Point)(V as object); // Specified cast is not …Run Code Online (Sandbox Code Playgroud) 我在PCL中有一个代码,我想迁移到.NetStandard.不幸的是,我的代码依赖于.Net反射,我无法找到以前可用的一些方法.所以这里是我在.NetStandard下找不到的方法或属性列表.任何人都能指出我如何重构我的代码吗?
Type.IsInstanceOfType()
Type.IsAssignableFrom()
Type.GetNestedTypes()
Type.GetConstructors()
Type.IsClass
Type.IsEnum
Type.IsValueType
Run Code Online (Sandbox Code Playgroud) 首先,我必须说,我在这里要做的都是关于点,而不是对象或其他任何东西。而我这里使用的OpenGL更多是为了计算。
所以这是我的问题。我想在我的 2d 上下文中显示一些 3d 点(例如 winform 或图像);为此,我编写了这个函数:(它使用 C# 并使用 OpenTK(OpenGL 包装器),但我确信如果您了解 OpenGL,无论您是否了解 C#,都可以理解它)
private Vector3 GetProjectedLocation(
Vector3 pointPosition,
Vector3 cameraPosition,
Matrix4 cameraRotationMatrix)
{
float horizentalFov = MathHelper.DegreesToRadians(60.0f);
float viewRatio = (float)this.RenderSize.Width / this.RenderSize.Height;
Vector3 cameraReference = new Vector3(0, 0, -1);
Vector3 transformedReference = Vector3.Transform(cameraReference, Matrix4.Invert(cameraRotationMatrix));
Vector3 cameraLookatTarget = cameraPosition + transformedReference;
Matrix4 modelMatrix = Matrix4.Identity;
Matrix4 viewMatrix = Matrix4.LookAt(cameraPosition, cameraLookatTarget, new Vector3(0, 1, 0));
Matrix4 projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(horizentalFov, viewRatio, 0.1f, 100.0f);
Matrix4 viewModelMatrix = viewMatrix * modelMatrix;
return Helper.Project( …Run Code Online (Sandbox Code Playgroud) 我有一个C++类,我想在C#中使用.为此,我试图编写另一个C++ DLL来包装这个类(它是另一个库的一部分),具有可调用的函数(使用"extern C和__declspec(dllexport)").我的想法是保持指向我的对象的指针并将其发送到包装器DLL中的函数,然后从那里调用该对象的方法.这看起来很好但是当对象具有解构器时会出现问题.
这是我的C++包装器代码:( Device是我的C++类/对象)
__declspec(dllexport) Status Device_open(Device* di, const char* uri)
{
Device dl;
Status status = dl.open(uri);
di = &dl;
return status;
}
__declspec(dllexport) void Device_Close(Device* di)
{
di->close();
}
Run Code Online (Sandbox Code Playgroud)
这是我的C#包装器代码:
[DllImport("Wrapper.dll")]
static extern Status Device_open(ref IntPtr objectHandler, IntPtr uri);
public static Device Open(string uri)
{
IntPtr handle = IntPtr.Zero;
Device_open(ref handle, Marshal.StringToHGlobalAnsi(uri));
return new Device(handle);
}
[DllImport("Wrapper.dll")]
static extern void Device_Close(IntPtr objectHandler);
public void Close()
{
Device_Close(this.Handle);
}
Run Code Online (Sandbox Code Playgroud)
这是在C#应用程序中测试代码:
Device d = Device.Open(di.URI);
d.Close();
Run Code Online (Sandbox Code Playgroud)
一切都是好的.问题在于,当我请求打开一个新设备时,将执行主C++对象的解构函数,因此我的关闭请求总是返回异常(因为它已经被关闭或被破坏);
我该怎么做才能防止这种情况发生?!
首先,我在服务器上安装了 xCache,我在很多服务器上都安装了 xCache,但是在几天后,除了在 apache 错误日志中出现此错误的空白页面之外,您什么也没有:
child pid XXXXX exit signal Segmentation fault
Run Code Online (Sandbox Code Playgroud)
据我所知,这意味着某种内存损坏。
所以我从 php.ini 中删除了 xCache 并安装了 APC。但现在情况更糟。一小时或更短/更多后服务器变得无响应。我可以在我网站的服务器状态中清楚地看到 W 模式下有很多连接。而且他们没有任何共同点。其中一些来自 Joomla(第一页),一些来自 vBulletin(论坛),一些来自其他自定义代码。如果我让它更长时间,我将在 Apache 错误日志中出现此错误:
Server reached MaxClients setting, consider raising the MaxClients setting
Run Code Online (Sandbox Code Playgroud)
Apache 处于 mod_php 和 mod_ruid2 模式。
这是挂起时服务器状态的结果:
Server uptime: 52 minutes 57 seconds
Total accesses: 31025 - Total Traffic: 279.0 MB
CPU Usage: u418.14 s64.28 cu0 cs0 - 15.2% CPU load
9.77 requests/sec - 89.9 kB/second - 9.2 kB/request
398 requests currently being processed, 27 idle …Run Code Online (Sandbox Code Playgroud) 我有两个几乎相同代码的例子.我可以从C#中检索一个数据,但我没有为另一个人提供正确的数据.他们来了:
效果很好
C++部分:
__declspec(dllexport) void** enumerateDevices(int *dIsize){
Array<DeviceInfo> dIArray;
Framewoek::enumerateDevices(&dIArray);
*dIsize = dIArray.getSize();
DeviceInfo dP[255];
for (int i = 0; i < dIArray.getSize(); i++)
dP[i] = dIArray[i];
void* p = dP;
return &p;
}
Run Code Online (Sandbox Code Playgroud)
C#部分:
[DllImport("Wrapper.dll")]
static extern IntPtr enumerateDevices(out int devicesSize);
public static DeviceInfo[] EnumerateDevices()
{
int devicesSize;
IntPtr arrayPointer = enumerateDevices(out devicesSize);
IntPtr[] array = new IntPtr[devicesSize];
Marshal.Copy(arrayPointer, array, 0, devicesSize);
DeviceInfo[] arrayObjects = new DeviceInfo[devicesSize];
for (int i = 0; i < devicesSize; i++)
arrayObjects[i] = new …Run Code Online (Sandbox Code Playgroud)