Evo C++ Library v0.5.1
|
Some Evo classes use Pointer Referencing to copy without allocating memory, improving performance.
This can be unsafe (dangerous) in certain situations so documentation for classes/methods that do this will have a warning and a link to this page.
Unsafe Pointer Referencing means an object is using (referencing) a pointer it does not own that may become invalid. If the actual owner frees this pointer then the object referencing it will be invalidated, and dereferencing the pointer will crash. You're safe as long as the object referencing the pointer is cleared/destroyed before the pointer is invalidated. If the pointer is never freed (ex: string literal) then this is always safe.
The following classes have certain methods that use this technique:
This technique is used by method overloads that take a raw pointer:
operator=(src)
set(src)
Safety:
unshare()
after Pointer Reference copy to force an unshared copycopy()
to force an unshared copyThe following classes rely on Pointer Referencing:
Safety:
The above classes are useful for passing arguments while making the intent of passing read-only data more clear. This is especially useful in multithreaded code that may pass data between threads (with approproiate synchronization).
See also: String Passing
Example:
Output:
This is safe as long as the function assumes referenced data will not persist.
A bad example: