set_array() calls clear() in order to free memory allocated to the old array and then sets a new array. This function is useful to set a memory- mapped array. Note that the array set by set_array() is not freed in clear() and the destructor of . set_array() can also set the size of the new array but the size is not used in search methods. So it works well even if the 2nd argument
| 171 | // used in search methods. So it works well even if the 2nd argument is 0 or |
| 172 | // omitted. Remember that size() and total_size() returns 0 in such a case. |
| 173 | void set_array(const void *ptr, std::size_t size = 0) { |
| 174 | clear(); |
| 175 | array_ = static_cast<const unit_type *>(ptr); |
| 176 | size_ = size; |
| 177 | } |
| 178 | void copy_array(const void* ptr, std::size_t num_bytes) { |
| 179 | clear(); |
| 180 | const std::size_t extra_padding = num_bytes % unit_size() == 0 ? 0 : 1; |
no test coverage detected