Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

RE: Turn off level in View, C++

$
0
0

Memory Leak!

[quote user="HDR_Coder"]MSWCharP levelName; levelName = convertStringto_wchar_t(line); DgnModelRefP modelRef = mdlModelRef_getActive();[/quote]

Your conversion function allocates memory, but you never dealloate it.

Use the standard library to avoid that sort of problem!

std::wstring convertStringto_wchar_t(string s)
{
  const size_t cSize = s.length () + 1;
  wchar_t* wc = new wchar_t[cSize];
  mbstowcs(wc, s.c_str (), cSize);
  std::wstring converted (wc);
  delete [] wc;
  return converted;
}

Usage...

const std::wstring& levelName = convertStringto_wchar_t (line);
...
mdlLevel_getIdFromName(&levid,modelRef,LEVEL_NULL_ID, levelName.c_str ());

Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>