// ---------------------------------------------------------------------------
// allocates memory needed to store a C string of length nLen
// ---------------------------------------------------------------------------
// allocates memory needed to store a C string of length nLen
// 2) sizeof(wxStringData) for housekeeping info
wxStringData* pData = (wxStringData*)
malloc(sizeof(wxStringData) + (nLen + EXTRA_ALLOC + 1)*sizeof(wxChar));
// 2) sizeof(wxStringData) for housekeeping info
wxStringData* pData = (wxStringData*)
malloc(sizeof(wxStringData) + (nLen + EXTRA_ALLOC + 1)*sizeof(wxChar));
pData->nRefs = 1;
pData->nDataLength = nLen;
pData->nAllocLength = nLen + EXTRA_ALLOC;
m_pchData = pData->data(); // data starts after wxStringData
m_pchData[nLen] = wxT('\0');
pData->nRefs = 1;
pData->nDataLength = nLen;
pData->nAllocLength = nLen + EXTRA_ALLOC;
m_pchData = pData->data(); // data starts after wxStringData
m_pchData[nLen] = wxT('\0');
{
wxStringData* pData = GetStringData();
if ( pData->IsShared() ) {
pData->Unlock(); // memory not freed because shared
size_t nLen = pData->nDataLength;
{
wxStringData* pData = GetStringData();
if ( pData->IsShared() ) {
pData->Unlock(); // memory not freed because shared
size_t nLen = pData->nDataLength;
memcpy(m_pchData, pData->data(), nLen*sizeof(wxChar));
}
wxASSERT( !GetStringData()->IsShared() ); // we must be the only owner
memcpy(m_pchData, pData->data(), nLen*sizeof(wxChar));
}
wxASSERT( !GetStringData()->IsShared() ); // we must be the only owner
if ( pData->IsShared() || pData->IsEmpty() ) {
// can't work with old buffer, get new one
pData->Unlock();
if ( pData->IsShared() || pData->IsEmpty() ) {
// can't work with old buffer, get new one
pData->Unlock();
else if ( pData->IsShared() ) {
pData->Unlock(); // memory not freed because shared
size_t nOldLen = pData->nDataLength;
else if ( pData->IsShared() ) {
pData->Unlock(); // memory not freed because shared
size_t nOldLen = pData->nDataLength;
}
// it's not important if the pointer changed or not (the check for this
// is not faster than assigning to m_pchData in all cases)
}
// it's not important if the pointer changed or not (the check for this
// is not faster than assigning to m_pchData in all cases)
{
wxStringData *pData = GetStringData();
size_t nLen = pData->nDataLength;
void *p = realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(wxChar));
{
wxStringData *pData = GetStringData();
size_t nLen = pData->nDataLength;
void *p = realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(wxChar));
}
// get the pointer to writable buffer of (at least) nLen bytes
wxChar *wxString::GetWriteBuf(size_t nLen)
{
}
// get the pointer to writable buffer of (at least) nLen bytes
wxChar *wxString::GetWriteBuf(size_t nLen)
{
// ---------------------------------------------------------------------------
// helper function: does real copy
// ---------------------------------------------------------------------------
// helper function: does real copy
memcpy(m_pchData, pszSrcData, nSrcLen*sizeof(wxChar));
GetStringData()->nDataLength = nSrcLen;
m_pchData[nSrcLen] = wxT('\0');
}
memcpy(m_pchData, pszSrcData, nSrcLen*sizeof(wxChar));
GetStringData()->nDataLength = nSrcLen;
m_pchData[nSrcLen] = wxT('\0');
}
// ---------------------------------------------------------------------------
// add something to this string
// ---------------------------------------------------------------------------
// add something to this string
STATISTICS_ADD(ConcatHit, 0);
// we have to grow the buffer
STATISTICS_ADD(ConcatHit, 0);
// we have to grow the buffer
// ---------------------------------------------------------------------------
// helper function: clone the data attached to this string
// ---------------------------------------------------------------------------
// helper function: clone the data attached to this string
- AllocCopy(dest, nCount, nFirst);
+ if ( !AllocCopy(dest, nCount, nFirst) ) {
+ wxFAIL_MSG( _T("out of memory in wxString::Mid") );
+ }
- AllocCopy(dest, nCount, GetStringData()->nDataLength - nCount);
+ if ( !AllocCopy(dest, nCount, GetStringData()->nDataLength - nCount) ) {
+ wxFAIL_MSG( _T("out of memory in wxString::Right") );
+ }
- AllocCopy(dest, nCount, 0);
+ if ( !AllocCopy(dest, nCount, 0) ) {
+ wxFAIL_MSG( _T("out of memory in wxString::Left") );
+ }