前言:最原始的發行版本代碼比較簡潔,我們從2017年ncnn第一次開源的版本閱讀mat的源碼。閱讀源碼味如嚼蠟,下面就開始吧!
目錄
構造函數
內存分配
數據成員
申請和釋放內存
引用計數
輔助函數
填充函數fill
參考
構造函數
ncnn提供了8種構造函數的方式。
// emptyMat();// vecMat(int w);// imageMat(int w, int h);// dimMat(int w, int h, int c);// copyMat(const Mat& m);// external vecMat(int w, float* data);// external imageMat(int w, int h, float* data);// external dimMat(int w, int h, int c, float* data);
其中包含了一維的vector,二維的image,三維數據,拷貝構造函數。
拷貝構造函數具體的寫法如下:
inline Mat::Mat(const Mat& m): dims(m.dims), data(m.data), refcount(m.refcount)
{if (refcount)NCNN_XADD(refcount, 1);w = m.w;h = m.h;c = m.c;cstep = m.cstep;
}
其中refco