cuda内存申请与释放
float* input_data_host = nullptr;
//cudaMallocHost(&input_data_host, batch_size * sizeof(float));
cudaMallocHost(&input_data_host, batch_size * 3 * this->INPUT_H * this->INPUT_W * sizeof(float));
checkRuntime(cudaFreeHost(input_data_host));
用new运算符动态的分配内存,用delete运算符释放这些内存
1、以int*为例:
1.1、动态创建
int *channelLen;
channelLen = new int[3];
1.2、动态释放
delete []channelLen;
channelLen = NULL;
2、以float**为例:
2.1、动态创建:
float** Info = NULL;
Info = new float*[10];
for(int i=0;i<10;i++)
{
Info[i]=new float[300];
memset(Info[i],0,300*sizeof(float));
}
2.2、动态释放
for(int i=0; i<10; i++)
{
delete []Info[i];
Info[i] = NULL;
}
delete []Info;
Info = NULL;
-----------------------------------
C++ 二维数组的动态创建和释放(new和delete)
https://blog.51cto.com/u_15127553/4234201