如何解决如何使用对齐的内存调用new [] / delete []运算符
在矩阵类中,我这样分配对齐的内存:
/*** main.cpp ***/
#include "matrix.hpp"
int main()
{
{
Matrix(15,17);
}
return 0;
}
/** matrix.hpp **/
class Matrix
{
private:
std::size_t width_,height_;
double* data_;
public:
Matrix(std::size_t width,std::size_t height);
~Matrix();
};
/** matrix.cpp **/
Matrix::Matrix(std::size_t width,std::size_t height)
: width_(width),height_(height)
{
data_ = new(std::align_val_t{64}) double[width_ * height_];
}
如何正确删除它?
我都尝试过
Matrix::~Matrix()
{
delete[] data_;
}
和
Matrix::~Matrix()
{
delete[](std::align_val_t{64},data_);
}
但是我得到了错误:
SIGTRAP (Trace/breakpoint trap)
ntdll!RtlIsNonEmptyDirectoryReparsePointAllowed 0x00007ffe5dc390e3
ntdll!RtlpNtMakeTemporaryKey 0x00007ffe5dc41512
ntdll!RtlpNtMakeTemporaryKey 0x00007ffe5dc4181a
ntdll!RtlpNtMakeTemporaryKey 0x00007ffe5dc4a7d9
ntdll!RtlGetCurrentServiceSessionId 0x00007ffe5db8081d
ntdll!RtlFreeHeap 0x00007ffe5db7fba1
msvcrt!free 0x00007ffe5bc09cfc
Matrix::~Matrix matrix.cpp:15
main main.cpp:16
__tmainCRTStartup 0x00000000004013c1
mainCRTStartup 0x00000000004014f6
其中第15行是包含delete []的行。
我正在Windows10上使用MSys2的g ++ 10.1。
edit:如果我在GSL 10.1的WSL下进行编译,则效果很好。因此,这可能是Windows端口引起的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。