This is the structure I'm using for maintaining a queue
struct image_data_struct {
uint32_t frame_id, no_of_files, tile_id, start_x, start_y, width, height;
float *tile_image_buffer;
image_data_struct():frame_id(), no_of_files(), tile_id(), start_x(), start_y(), width(), height(), tile_image_buffer(NULL) {
tile_image_buffer = (float*)malloc(300*300*3*sizeof(float));
}
~image_data_struct(){
if(tile_image_buffer != NULL){
free(tile_image_buffer);
tile_image_buffer = NULL;
}
}
};
image_data_struct tile_img;
std::queue<image_data_struct> imgQ;
int main()
{
float test_img[300*300*3];
memset(test_img,2,300*300*3*sizeof(float));
memcpy(tile_img.tile_image_buffer,&test_img,sizeof(test_img));
imgQ.push(tile_img);
printf("\nSize of q: %d \n",imgQ.size());
printf("\nimg addr %p \n",imgQ.front().tile_image_buffer);
imgQ.pop();
return 0;
}
I'm using a destructor for freeing the buffer. so I'm getting segmentation fault when the structure goes out of scope, i.e while calling free