context.marshal_as每次调用都需要更长的时间来执行

时间:2014-04-17 07:23:23

标签: c++ visual-studio-2008 marshalling unmanaged

我有一个调试功能可以将一些图像导出到硬盘,它们位于一个非托管的C ++ DLL中。该函数有两个参数,这些参数被编组为一个完整文件名的字符串。这个功能很多次被调用。在执行应用程序时,我注意到它随着时间的推移变得越来越慢,我将其追溯到此功能(感谢SlimTune!)。如果我留下编组代码,但我会注释掉这一行:

std::string completeFileName = m_csTempFolder + stdSubFolderName + stdFileName + ".bmp";

替换为:

std::string completeFileName = "C:\\Users\\pedro\\AppData\\Local\\Temp\\BatchProc64\\test.bmp";

我不再有问题了。它看起来问题是将刚刚封送的字符串与字符串常量混合成一个新字符串。有人可以解释一下吗? 应用程序使用的内存保持稳定,没有应用程序崩溃 我正在使用Visual Studio 2008和.NET 3.5 提前谢谢!

功能代码的开头如下:

// Export the 32 bit buffer into a 8 bit buffer, then write it into a file, used for trace image generation (app debug)
void CMtxSurface::ExportTraceImage32bit(System::String^ subFolderName, System::String^     fileName, MIL_ID img32bit)
{
// The [Conditional("_TRACE_")] doesn't work in C++ compiler so we need to use ifdef...
#ifdef _TRACE_

marshal_context context;
std::string stdSubFolderName = context.marshal_as<std::string>(subFolderName);
std::string stdFileName = context.marshal_as<std::string>(fileName);

std::string completeFileName = m_csTempFolder + stdSubFolderName + stdFileName + ".bmp";
//  std::string completeFileName = "C:\\Users\\pedro\\AppData\\Local\\Temp\\BatchProc64\\test.bmp";

0 个答案:

没有答案