You are not logged in.
Pages: 1
If we have a FAST_JSON DVD - TDocVariantData.InitFast, how to actually add Variants by reference to it?
AddItem will store sent value with SetVariantByValue, same for AddValue (I haven't tried aValueOwned in mORMot2, just using ver1 for now).
Last edited by igors233 (2022-07-22 13:31:41)
Offline
The only option I see is to use SetCapacity, SetCount, then directly copy by reference to VValues[].
The fact that we force SetVariantByValue() is that copying by reference may trigger some GPF or leaks if not properly used, since there is no reference counting, just passing pointers.
What do you want to store varByRef variants?
The performance difference won't be noticeable - it may even be slower if it contains mostly simple types. And for RawUtf8 variant strings, they will use RawUtf8 reference counting, so are fast too.
Online
> The fact that we force SetVariantByValue() is that copying by reference may trigger some GPF or leaks if not properly used, since there is no reference counting, just passing pointers.
I'm mostly storing larger json objects and they could be added to several other objects so storing by reference would be ideal to save memory and increase speed.
Sometimes it could also be used to easily update all objects (change one property and it changes to all).
Looking at code, is dvoValueCopiedByReference designed to handle json objects variants? For example using AddNameValuesToObject with json object, would dereference it anyway, create a copy?
Offline
Values are already copied by reference from one TDocVariantData to another, if you use "fast" TDocVariantData, dvoValueCopiedByReference.
It means the VNames[] and VValues[] arrays are copied by reference, i.e. using reference counting.
Online
Pages: 1