. Vadims. , , . 3x3 4x4. , :)
, . - , .
. (, a=b) ( ).
, , . -, void Matrix.TransFormMe() on b, , (a b) .
, "" , .
, API - . void TransformMe()' member transforming the contained matrix, Matrix contains only a Matrix GetTransformed() `, .
. MFC CString copy-on-write, .NET a String . (, StringBuilder), . Copy-On-Write , API , .
, , (.. ), - .
- copy-on-write boost, , .. Pseudocode :
class CowPtr<T>
{
refcounting_ptr<T> m_actualData;
public:
void MakeUnique()
{
if (m_actualData.refcount() > 1)
m_actualData = m_actualData.DeepCopy();
}
}
class MatrixData // not visible to user
{
std::vector<...> myActualMatrixData;
}
class Matrix
{
CowPtr<MatrixData> m_ptr;
double operator()(int row, int col) const
{
return m_ptr->GetElement(row, col);
}
void Transform()
{
m_ptr.MakeUnique();
m_ptr->Transform();
}
}