Creates new shared data for instance - If capacity is specified (>0) then create empty shared data with initial reserved capacity - If capacity is not specified (<=0) then create empty shared data with no initial capacity
| 24 | // - If capacity is specified (>0) then create empty shared data with initial reserved capacity |
| 25 | // - If capacity is not specified (<=0) then create empty shared data with no initial capacity |
| 26 | void Bytes::newData(size_t capacity /*= 0*/) { |
| 27 | //MEMF("Bytes is creating own data with capacity %u", capacity); |
| 28 | //MEM("newData: Creating new data..."); |
| 29 | Data* data = new Data(); |
| 30 | if (data == nullptr) { |
| 31 | ERROR("Bytes failed to allocate empty data buffer"); |
| 32 | throw std::runtime_error("Failed to allocate empty data buffer"); |
| 33 | } |
| 34 | //MEM("newData: Created new data"); |
| 35 | if (capacity > 0) { |
| 36 | //MEMF("newData: Reserving data capacity of %u...", capacity); |
| 37 | data->reserve(capacity); |
| 38 | //MEM("newData: Reserved data capacity"); |
| 39 | } |
| 40 | //MEM("newData: Assigning data to shared data pointer..."); |
| 41 | _data = SharedData(data); |
| 42 | //MEM("newData: Assigned data to shared data pointer"); |
| 43 | _exclusive = true; |
| 44 | } |
| 45 | |
| 46 | // Ensures that instance has exclusive shared data |
| 47 | // - If instance has no shared data then create new shared data |