C++ how to delete a structure?

前端 未结 11 1139
生来不讨喜
生来不讨喜 2020-12-31 03:42

Structure I created:

   struct VideoSample
  { 
      const unsigned char * buffer;
      int len;
  };

   VideoSample * newVideoSample = new VideoSample;
          


        
11条回答
  •  独厮守ぢ
    2020-12-31 04:03

    To Allocate -> VideoSample * newVideoSample = new VideoSample;

    To Delete -> delete newVideoSample;

    If you deleting the object in the same context, you better just allocate it on the stack. If you deleting it outside the context don't forget to pass a reference.

    And most important, don't delete if your about to exit process, it's pointless :P

提交回复
热议问题