我创建了两个名为X&Y的列表.这两个列表的类型不同.(即List<class_A> X&List<class_B> Y).
这两个列表中的值都不同.但是这DateTime两个列表中都有一个字段.
我需要根据date字段对这些列表进行排序.
我有单独的函数来打印列表A和列表B的详细信息.
假设排序列表看起来像
我的目的是遍历此列表并调用相应的函数来显示详细信息.即,如果元组来自列表A,则调用函数打印列表A的详细信息,反之亦然.
在我的C++ DLL中,我从字节数组创建Mat:
BYTE * ptrImageData; //Image data is in this array passed to this function
Mat newImg = Mat(nImageHeight, nImageWidth, CV_8UC3, ptrImageData);
Run Code Online (Sandbox Code Playgroud)
使用一些灰色阴影而不是原始阴影创建图像.
这是从字节数组创建Mat的正确方法吗?
请参阅代码
ptrImageData从C#代码传递给C++ DLL.
传递图像数据的C#代码
System.Drawing.Image srcImage //Has the image
MemoryStream ms = new MemoryStream();
Marshal.FreeHGlobal(ptrImageData);
srcImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imgArray = ms.ToArray();
ms.Dispose();
int size1 = Marshal.SizeOf(imgArray[0]) * imgArray.Length;
IntPtr ptrImageData = Marshal.AllocHGlobal(size1);
Marshal.Copy(imgArray, 0, ptrImageData, imgArray.Length);
//Calling C++ dll function
ProcessImage(ptrImageData, srcImage.Width, srcImage.Height);
Marshal.FreeHGlobal(ptrImageData);
Run Code Online (Sandbox Code Playgroud) 我最近使用boost的新stacktrace库实现了堆栈跟踪日志记录:
int debugErrorCallback(int status, const char* func_name, const char* err_msg, const char* file_name, int line, void* userdata)
{
boost::stacktrace::stacktrace stacktrace(4, 10); //skipped 4 frames include cv::error, this function and 2 in boost::stacktrace ctor
std::cout << boost::stacktrace::detail::to_string(stacktrace.as_vector().data(),
stacktrace.size()) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
在我的开发机器上对其进行了测试,结果完美:
0# cv::arithm_op at d:\src\opencv_24\modules\core\src\arithm.cpp:1293
1# cv::addWeighted at d:\src\opencv_24\modules\core\src\arithm.cpp:2127
2# MyApplication::myFunction at d:\src\path\to\my\file.cpp:226
3# MyApplication::myOtherFunction at d:\src\path\to\my\other_file.cpp:146
...
Run Code Online (Sandbox Code Playgroud)
我将新的应用程序版本部署到生产中。不幸的是,在生产机器上,模块中的框架仅解析为模块名称:
0# cv::addWeighted in opencv_core2413
1# cv::addWeighted in opencv_core2413
2# 0x00007FF7D0A0B56B in MyApplication
3# 0x00007FF7D0A0B2ED in MyApplication
...
Run Code Online (Sandbox Code Playgroud)
我调试了boost的实现,stacktrace …
我有一个简单的Sum扩展:
public static int? SumOrNull<TSource>(this IEnumerable<TSource> source, Func<TSource, int> projection)
{
return source.Any()
? source.Sum(projection)
: (int?)null;
}
Run Code Online (Sandbox Code Playgroud)
但它会导致 System.OverflowException: Arithmetic operation resulted in an overflow.
我想要做的是这样的事情:
public static ulong? SumOrNull<TSource>(this IEnumerable<TSource> source, Func<TSource, int> projection)
{
return source.Any()
? source.Sum(projection)
: (ulong?)null;
}
Run Code Online (Sandbox Code Playgroud)
但Linq Sum没有超载,因此返回ulong和编译错误.任何方式使这项工作?
据我所知,Thread.Sleep(0)只为具有相同或更高优先级的另一个线程提供时间片.我做了一些测试应用:
class Program
{
public static void ThreadMethod()
{
for (int i = 0; i < 300; i++)
{
Thread.Sleep(0);
Console.WriteLine("{0} ThreadProc: {1}, prio {2} ", Thread.CurrentThread.ManagedThreadId,
i, Thread.CurrentThread.Priority);
}
}
public static void Main()
{
Thread.CurrentThread.Priority = ThreadPriority.Normal;
Thread t = new Thread(new ThreadStart(ThreadMethod));
t.Priority = ThreadPriority.Highest;
Thread t2 = new Thread(new ThreadStart(ThreadMethod));
t2.Priority = ThreadPriority.Lowest;
Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)1;
t.Start();
t2.Start();
t2.Join();
t.Join();
}
}
Run Code Online (Sandbox Code Playgroud)
这是模拟单核CPU,据我所知这里应该只执行主要具有最高优先级的线程,但我看到:低prio线程不断更改高prio每个操作 
线程互相改变.(当然在开始和结束时有不同的情况,但最高线程应该总是得到更多的时间片)
我在属性值计算中看到了非常奇怪的行为.我有一个属性HasChanged,如果它的任何依赖属性为true,则为true.但是我得到了一个结果 - 所有参数都是错误的,结果都是正确的.我正在使用MVVM Light框架,每个属性都是INotifyPropertyChanged
这是辅助函数
private static bool PropertyWrapper(bool value, [CallerMemberName] string callerName = "")
{
Logger.Debug($"[{callerName}: {value}]");
return value;
}
private static T PropertyWrapper<T>(Expression<Func<T>> property)
{
var compiled = property.Compile();
var result = (T)compiled.DynamicInvoke();
Logger.Debug($"[{GetName(property)}: {result}]");
return result;
}
private static string GetName<T>(Expression<Func<T>> expr)
{
var mexpr = expr.Body as MemberExpression;
if (mexpr == null) return "(null)";
if (mexpr.Member == null) return "((null))";
return mexpr.Member.Name;
}
Run Code Online (Sandbox Code Playgroud)
这是代码
public virtual bool HasChanged => PropertyWrapper(new[] {
PropertyWrapper(() => TitleChanged),
PropertyWrapper(() => …Run Code Online (Sandbox Code Playgroud) c# ×5
linq ×3
c++ ×2
.net ×1
any ×1
boost ×1
ienumerable ×1
opencv ×1
stack-trace ×1
visual-c++ ×1