In Tact, loadRef()
and preloadRef()
functions are used to retrieve data from a reference cell into a variable, without any promises or async involved.
However, they differ in their behavior when dealing with reference cells that contain slices.
loadRef() consumes the reference to the slice and returns its contents. This means that loadRef() can only be used once on a reference cell that contains a slice.
preloadRef() loads the contents of the slice in the background and returns a new reference to the slice. This allows preloadRef() to be used multiple times on a reference cell that contains a slice, without consuming the original reference.
Regarding your question, using preloadRef() should not cause a crash or result in reading wrong data from another memory space, as long as it is used appropriately. However, it is important to understand the difference between the two functions and use them accordingly to avoid unexpected behavior in your program.
In Tact, or the first question I asked, I used this to solve the problem.
let dataCell: Cell = msg.custom_payload!!;
let sc: Slice = dataCell.beginParse(); // set a new slice
self.value = sc.loadUint(256);
self.individual_content = sc.loadRef();