mat
ファイルをC++コードにインポートしています。データをインポートし、計算を実行して別の場所に保存した後、元のデータが占有していたメモリを解放したいと思います。mxGetData()によって割り当てられたメモリを解放する方法
これを実行する特定の機能はありますか? mxGetData()
によって返されたポインタを削除するだけでメモリが解放されますか?
この私がオブジェクトプログラムを削除するとき、私はマットファイル
#ifndef READMAT_H
#define READMAT_H
#include "mat.h"
#include "matrix.h"
#include "mex.h"
#include "program_exception.h"
#include "stdint.h"
class readmat
{
private:
const size_t *dimarray;
const char **dir;
MATFile *pmat;
int ndir;
mxArray *painfo,*pa;
const char *file;
int minute;
int second;
const char *name;
const char *name1;
bool isdouble;
no_mat_exception noMAT;
public:
//with default value
readmat(const char *f);
// get number of dimensions
int getnumbrofdimensions() const;
// get pointer to array
void* getarraypointer() const;
// get pointer to each dimension size
const size_t* dimensionpointer() const;
//number of elements
int numberofelements() const;
~readmat();
};
#endif
次をインポートするために作成したクラスは、ここでCPP実装
#include "readmat.h"
#include <iostream>
#include "mat.h"
#include "matrix.h"
#include "mex.h"
using namespace std;
// set the file name
readmat::readmat(const char *f)
{
file = f;
pmat = matOpen(file, "r");
if (pmat == NULL) {
throw noMAT;
}
else
{
dir = (const char **)matGetDir(pmat, &ndir);
if (dir == NULL) {
printf("Error reading directory of file %s\n", file);
}
else if (ndir > 1)
{
cout << "The number of variables are larger than 1" << endl;
}
else
{
mxFree(dir);
matClose(pmat);
pmat = matOpen(file, "r");
if (pmat == NULL) {
throw noMAT;
}
else
{
painfo = matGetNextVariableInfo(pmat, &name);
matClose(pmat);
}
pmat = matOpen(file, "r");
if (pmat == NULL) {
throw noMAT;
}
else
{
pa = matGetNextVariable(pmat, &name1);
matClose(pmat);
}
}
}
}
int readmat::getnumbrofdimensions() const
{
return mxGetNumberOfDimensions(painfo);
}
void* readmat::getarraypointer() const
{
//return mxGetPr(pa);
return mxGetData(pa);
}
const size_t* readmat::dimensionpointer() const
{
return mxGetDimensions(painfo);
}
int readmat::numberofelements() const
{
return mxGetNumberOfElements(painfo);
}
readmat::~readmat()
{
mxFree(pa);
mxFree(painfo);
}
ですが、ファイル内のブレークポイントをトリガfree.c。
それは大変効果があります。 –