ホーム » Xcode » ostrstream の利用でメモリリーク

2013年8月
 123
45678910
11121314151617
18192021222324
25262728293031

カテゴリー

アーカイブ

ブログ統計情報

  • 79,383 アクセス



ostrstream の利用でメモリリーク

次の様なコードでメモリリーク.freeze(false) がなかったのが原因.


tstring To_tstring (const double v,const int w=0,const int p=6,const long f=0) {
  tstring str ;
  std::ostrstream strBuf ;
  if (f != 0) {
    strBuf.flags(f) ;
    }
  {
    strBuf.width(w) ;
    strBuf.precision(p) ;
    }
  {
    strBuf << v ;
    strBuf << std::ends ;
    }
  {
    str = strBuf.str() ;
  // strBuf.rdbuf()->freeze(false) ;
    }
  return str ;
  }


Detected memory leaks!
Dumping objects ->
{385} normal block at 0x00038168, 512 bytes long.
Data: < 1.05 > 20 20 31 2E 30 35 00 CD CD CD CD CD CD CD CD CD
{363} normal block at 0x00037F20, 512 bytes long.
Data: <233.50 > 32 33 33 2E 35 30 00 CD CD CD CD CD CD CD CD CD
{339} normal block at 0x00037C70, 512 bytes long.
Data: < 967 > 20 20 20 39 36 37 00 CD CD CD CD CD CD CD CD CD
{315} normal block at 0x00037A28, 512 bytes long.
Data: < 875 > 20 20 20 38 37 35 00 CD CD CD CD CD CD CD CD CD
{291} normal block at 0x000377E0, 512 bytes long.
Data: < 997 > 20 20 20 39 39 37 00 CD CD CD CD CD CD CD CD CD
{269} normal block at 0x00037598, 512 bytes long.
Data: < 1.08 > 20 20 31 2E 30 38 00 CD CD CD CD CD CD CD CD CD
{245} normal block at 0x00037350, 512 bytes long.
Data: < 955 > 20 20 20 39 35 35 00 CD CD CD CD CD CD CD CD CD
{223} normal block at 0x00037108, 512 bytes long.
Data: < 1.15 > 20 20 31 2E 31 35 00 CD CD CD CD CD CD CD CD CD
{201} normal block at 0x00036EC0, 512 bytes long.
Data: < 1.02 > 20 20 31 2E 30 32 00 CD CD CD CD CD CD CD CD CD
{169} normal block at 0x000369B8, 512 bytes long.
Data: < 1.06 > 20 20 31 2E 30 36 00 CD CD CD CD CD CD CD CD CD
{143} normal block at 0x00036770, 512 bytes long.
Data: < 1003 > 20 20 31 30 30 33 00 CD CD CD CD CD CD CD CD CD
Object dump complete.
スレッド 0xDEC 終了、終了コード 0 (0x0)。
プログラム ‘C:\…\DmpFS\Debug\DmpFS.exe’ はコード 0 (0x0) で終了しました。


MSDN strstreambuf::freeze


2013/08/26
上のコードを Xcode でビルドすると,strBuf.flags(f) の所で
    /Volumes/…/t_string.hxx:47:10: No matching member function for call to ‘flags’
  利用する前に fmtflags 型にして利用する様に変更.
    std::ios_base::fmtflags f = std::ios_base::fmtflags(f_) ;


2013/08/28
_UNICODE に対応できなかったので,ostringstream を利用する様に変更.
  tstring To_tstring (const double v,const int w=0,const int p=6,const unsigned f_=std::ios::fixed) {
    tstring str ;
  #ifdef _UNICODE
    std::wostringstream strBuf ;
  #else
    std::ostringstream strBuf ;
  #endif
    std::ios_base::fmtflags f = std::ios_base::fmtflags(f_) ;
    if (f != 0) { strBuf.flags(f) ; }
    strBuf.width(w) ;
    strBuf.precision(p) ;
    strBuf << v ;
    str = strBuf.str() ;
    return str ;
    }

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。