NANA
mat.cpp
浏览该文件的文档.
1#include "..\include\core\mat.h"
15#pragma once
16
17namespace NANA {
18
19
20template<typename _T>
22{
23 m_rows = 0;
24 m_cols = 0;
25 m_stride = 0;
26 m_data = nullptr;
27 m_datamanager = nullptr;
28}
29
30template<typename _T>
31Mat<_T>::Mat(int rows, int cols)
32{
33 m_rows = rows;
34 m_cols = cols;
35 m_stride = cols * sizeof(_T);
36 m_stride = m_stride + m_stride % 32;
37 m_datamanager = new CDataManager();
38 this->allocateMemory(m_rows, m_stride);
39}
40
41template<typename _T>
43{
44 this->release();
45}
46
47
48
49template<typename _T>
50void Mat<_T>::allocateMemory(const int32_t rows, const int32_t m_stride)
51{
52 m_data = reinterpret_cast<char*>(malloc(rows * m_stride));
53}
54
55template<typename _T>
56void Mat<_T>::releaseMemory()
57{
58 if (nullptr != m_data) {
59 delete[] m_data;
60 m_data = nullptr;
61 }
62}
63
64template<typename _T>
65void Mat<_T>::release()
66{
67 if (nullptr == m_datamanager)
68 return;
69 if ((m_datamanager->m_refcount--) != 1)
70 return;
71 this->releaseMemory();
72 deleteSafe(m_datamanager);
73}
74
75
76
77}
78
高效矩阵运算类
Definition: mat.h:31
virtual ~Mat()
析构函数
Definition: mat.cpp:42
Mat()
Definition: mat.cpp:21
void deleteSafe(_T *&p)
Definition: safememory.hpp:40