【发布时间】:2013-07-13 05:52:44
【问题描述】:
我对 C++ 还是很陌生。我正在将文件的内容读入如下结构:
struct wavObj {
uint8_t *dataBuffer; // the data
int readFile( const char *filePath );
};
int wavObj::readFile( const char *filePath ) {
FILE *file = NULL; // File pointer
file = fopen( filePath, "rb" );
dataBuffer = new uint8_t[data_Size];
fread(dataBuffer, data_Size, 1, file);
fclose(file);
return 0;
}
我是否需要在某处使用删除运算符来删除 wavObj.dataBuffer?当程序结束时这个结构会被破坏吗,内存分配也会被破坏吗?如果没有,我可以制作一个使用删除运算符的析构函数吗?
【问题讨论】:
-
使用
std::vector不会有问题。 -
谢谢大家。好好阅读@MarkGarcia,我想我会尝试学习一些关于向量的知识。如果这很重要,这是我正在阅读的 wav 文件。
标签: c++ class struct new-operator delete-operator