Note: For var-len strings, Swap is more efficient than a rustic exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters.
SWAP keyword
Re: SWAP keyword
Proposed note improvement:
Re: SWAP keyword
Your Poposal: -> OK, for String
I'd like you, however, to add something like:
The same applies to Ptr's, even in UDT's (Ptr's swapped, no change to 'pointed to' values).
<OT>
just had a server failure (trying to post):
503
Service Unavailable
The server is temporarily busy, try again later!
</OT>
I'd like you, however, to add something like:
The same applies to Ptr's, even in UDT's (Ptr's swapped, no change to 'pointed to' values).
<OT>
just had a server failure (trying to post):
503
Service Unavailable
The server is temporarily busy, try again later!
</OT>
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: SWAP keyword
Hi fxm. Not sure than rustic is neutral enough. After all, some may have a good reason to use the "rustic" case in some special case. Maybe "classical", or "basic" would be more suitable.fxm wrote:Proposed note improvement:Note: For var-len strings, Swap is more efficient than a rustic exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters.
I have a question that bothers me. If the UDT are swapped more efficently than the standard types, at least for the INTEGER. Would you recommend to encapsulate the INTEGER in a UDT, if we were to be extremist (or simply if we have a real performance challenge in this context)?
Re: SWAP keyword
Tourist Trap wrote:Hi fxm. Not sure than rustic is neutral enough. After all, some may have a good reason to use the "rustic" case in some special case. Maybe "classical", or "basic" would be more suitable.fxm wrote:Proposed note improvement:Note: For var-len strings, Swap is more efficient than a rustic exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters.
Okay both for your remarks:MrSwiss wrote:Your Poposal: -> OK, for String
I'd like you, however, to add something like:
The same applies to Ptr's, even in UDT's (Ptr's swapped, no change to 'pointed to' values).
Note: For var-len strings, Swap is more efficient than a classical exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters. The same applies to Ptr's, even in UDT's (Ptr's values swapped, no change to 'pointed to' data).
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: SWAP keyword
Hi fxm,fxm wrote: Note: For var-len strings, Swap is more efficient than a classical exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters. The same applies to Ptr's, even in UDT's (Ptr's values swapped, no change to 'pointed to' data).
thanks first,
then just to offer you an alternative to think of. I would make it differently. Here we see a general case, where a variable type is compound of a header + data. What is faster obviously is to move the headers alone, without the burden of the data. To illustrate this, we can then derivate both the case of the string (header = descriptor) and the pointer (header = address).
Of course I dont ask you to express things like that, because the term header is probably already dedicated to very different cases. It's still how I would try to reformulate if I knew the right wording. Anyway your proposal already gives most of the informations, just not the general principle - maybe.
Re: SWAP keyword
Encapsulate an Integer in a UDT does not improve the efficiency of 'Swap'.Tourist Trap wrote:I have a question that bothers me. If the UDT are swapped more efficently than the standard types, at least for the INTEGER. Would you recommend to encapsulate the INTEGER in a UDT, if we were to be extremist (or simply if we have a real performance challenge in this context)?
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: SWAP keyword
Yes I think that now I see why. If I'm on the right path with my previous intuition. Here, the *header* is of the same weight as the *data*, so no win.fxm wrote: Encapsulate an Integer in a UDT does not improve the efficiency of 'Swap'.
There is a mystery then, why is there a slight advantage still obvservable when using swap with integers, rather than when we have the classical use of temp?
Re: SWAP keyword
Perhaps:Tourist Trap wrote:then just to offer you an alternative to think of. I would make it differently. Here we see a general case, where a variable type is compound of a header + data. What is faster obviously is to move the headers alone, without the burden of the data. To illustrate this, we can then derivate both the case of the string (header = descriptor) and the pointer (header = address).
Of course I dont ask you to express things like that, because the term header is probably already dedicated to very different cases. It's still how I would try to reformulate if I knew the right wording. Anyway your proposal already gives most of the informations, just not the general principle - maybe.
Note: For var-len strings, Swap is more efficient than a classical exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters.
More generally, when the data are referenced by a pointer, alone or within a descriptive structure (a UDT, for example), it is most efficient to swap only the pointers values or the descriptive structures fields without accessing data themselves.
Re: SWAP keyword
I'd swap the two parts:fxm wrote:Perhaps:
Note: For var-len strings, Swap is more efficient than a classical exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters.
More generally, when the data are referenced by a pointer, alone or within a descriptive structure (a UDT, for example), it is most efficient to swap only the pointers values or the descriptive structures fields without accessing data themselves.
start with the general part (sort of: in principle)
then:
use the string (as a example) for a struct copy vs. comlpete round the circle assigning.
Last edited by MrSwiss on May 04, 2019 19:21, edited 1 time in total.
Re: SWAP keyword
For example, Swap uses an internal register as temporary variable.Tourist Trap wrote:There is a mystery then, why is there a slight advantage still obvservable when using swap with integers, rather than when we have the classical use of temp?
Re: SWAP keyword
Next proposal:
Taken into account MrSwiss remark below.
[edit]Note:More generallyGenerally, when the data are referenced by a pointer, alone or within a descriptive structure (a UDT, for example), it is most efficient to swap only the pointers values or the descriptive structures fields without accessing data themselves.
That's why for var-len strings, Swap is more efficient than a classical exchange by circular assignments (using a third temporary string), because only the strings descriptors are exchanged rather than all strings data characters.
Taken into account MrSwiss remark below.
Re: SWAP keyword
Thumbs up, full marks, thanks ... just use *generally" as first word (after NOTE:)
by simply deleting "more"
by simply deleting "more"
Re: SWAP keyword
KeyPgSwap → fxm [Reworded Note]
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: SWAP keyword
Thanks a lot. This little note now helps understanding the logic behind.fxm wrote:KeyPgSwap → fxm [Reworded Note]
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: SWAP keyword
I think it’s enough to say that with variable-length strings, the descriptors are swapped without reallocating any string data memory.
And for UDTs, the contents of the structures are swapped without any operators or methods being called.
I don’t think it is worth discussing efficiency. The semantics are more important, and readers who are interested in efficiency should expect swapping just the descriptors to be more efficient anyway.
Overall, I think the documentation should be “as simple as possible, but no simpler”.
I’m also wary of over-documenting things. If a specific behaviour is documented in one version, then if it is changed it in future, that means breaking documented behaviour.
And for UDTs, the contents of the structures are swapped without any operators or methods being called.
I don’t think it is worth discussing efficiency. The semantics are more important, and readers who are interested in efficiency should expect swapping just the descriptors to be more efficient anyway.
Overall, I think the documentation should be “as simple as possible, but no simpler”.
I’m also wary of over-documenting things. If a specific behaviour is documented in one version, then if it is changed it in future, that means breaking documented behaviour.