Fragment:
fn getPtr(from_address: [] const u8) !*ConfirmationMessage {
mutex.lock();
var gop = try map.getOrPut(from_address);
mutex.unlock();
// there is a CM in the map, if it has old data free this
if (gop.found_existing) {
if (gop.value_ptr.value) |buffer_ptr| {
allocator.free(buffer_ptr);
gop.value_ptr.value = null;
}
}
// there is no CM in the map under this key, so create an empty new one
else {
gop.value_ptr = try allocator.create(ConfirmationMessage);
gop.value_ptr.* = ConfirmationMessage.init(null);
}
const real_ptr = map.getPtr(from_address);
if (real_ptr) |ptr| {
std.debug.assert(ptr == gop.value_ptr);
return ptr;
}
unreachable;
}
The `std.debug.assert()` shows that the two pointers are NOT the same. When I set a pointer with getOrPut() directly, then getPtr() delivers a different one.
How do I get the real value pointer stored in the map? And why is a second one created and delivered?