I have implemented a basic pImpl set-up that is basically this example: Is the pImpl idiom really used in practice?.
Most pImple implementations I find online never show any method examples. The rule of thumb seems to be to hide all private members/methods in the pImple. The problem I am running into is I have a public method that looks sort of like this:
bool Foo::Bar(const void* data, size_t size)
{
if( size > 0 )
{
if(data == nullptr)
return false;
size_t newSize = m_size + size;
if ( newSize > m_capacity )
{
m_capacity = GROW_FACTOR*newSize;
void* newMem = Malloc(m_capacity);
if ( m_size > 0 )
::memcpy(newMem, m_data, m_size);
if ( m_data )
Free(m_data);
m_data = (char*)newMem;
}
::memcpy(m_data + m_size, data, size);
m_size += size;
}
return true;
}
Should this be in the pImpl? If not it seems a bit ugly to put pImpl->member every few words. How do you go about this?