SRD

snippets

SRD
Jun 3rd, 2020
1,273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. typedef struct {
  2.     uint16_t index;
  3.     uint8_t tok;
  4.     uint8_t blen;
  5. } record_info_t;
  6.  
  7. typedef struct {
  8.     uint16_t index;
  9.     unsigned int n_records;
  10.     record_info_t *records;
  11. } disc_info_t;
  12.  
  13.  
  14. /* Are the following two code snippets doing the same thing? I seem to be losing data using smart pointers and think maybe the push_back isn't copying deep enough, or something along those lines. */
  15.  
  16.     disc_info_t *discs = new disc_info_t[disc_map->size()];
  17.  
  18.     size_t i = 0;
  19.  
  20.     for (auto& [index, disc] : *disc_map)
  21.         discs[i++] = disc;
  22.  
  23. ---
  24.  
  25.     std::shared_ptr<std::vector<disc_info_t>> discs =
  26.         std::make_shared<std::vector<disc_info_t>>(disc_map->size());
  27.  
  28.     // is this losing data?j specifically, records within discs?
  29.     for (auto& [index, disc] : *disc_map)
  30.         discs->push_back(disc);
Advertisement
Add Comment
Please, Sign In to add comment