MCPcopy Create free account
hub / github.com/attermann/microReticulum / newData

Method newData

src/microReticulum/Bytes.cpp:26–44  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
26void 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

Callers

nothing calls this directly

Calls 1

reserveMethod · 0.80

Tested by

no test coverage detected