Skip to content

Commit

Permalink
Change メモリ確保の最適化(そのかわり使用量が増える)
Browse files Browse the repository at this point in the history
  • Loading branch information
niki committed Apr 10, 2024
1 parent b953a7e commit 5989abe
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sakura_core/mem/CMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,26 @@ void CMemory::AllocBuffer( int nNewDataLen )
pWork = malloc_char( nWorkLen );
m_nDataBufSize = nWorkLen;
}else{
#if 1
// use aligned 'nkmm
size_t alignedSize = 8;
while (alignedSize < nWorkLen) {
alignedSize *= 2;
}
nWorkLen = alignedSize;

// 2014.06.25 有効データ長が0の場合はfree & malloc
if( m_nRawLen == 0 ){
free( m_pRawData );
m_pRawData = NULL;
pWork = malloc_char( nWorkLen );
}else{
if( m_nDataBufSize < nWorkLen ){
pWork = (char*)realloc( m_pRawData, nWorkLen );
}
}
m_nDataBufSize = nWorkLen;
#else
/* 現在のバッファサイズより大きくなった場合のみ再確保する */
if( m_nDataBufSize < nWorkLen ){
// 2014.06.25 有効データ長が0の場合はfree & malloc
Expand All @@ -326,6 +346,7 @@ void CMemory::AllocBuffer( int nNewDataLen )
}else{
return;
}
#endif
}


Expand Down

0 comments on commit 5989abe

Please sign in to comment.