
Hi, I'm looking for a use case where the use of swap_in_place (or whatever is renamed) is not followed/preceded by a copy. When I need to send a message I need to copy the information to send in a buffer. I gues that in this case the use of swap (copy) is the function to use. Can somene help me to identify a real use case on which the swap_in_place can be used to send a message that do not need to be initialized before sending? When I receive a message, I will need to store some of the messages information on application context, store them on local variables or pass them to other functions. All this suppose a copy from the buffer to the different kinds of native storage. I gues that swap (copy) should be used in this case also. The example of Terry reveives a array of ints and makes a swap_in_place, but do nothing with. Someone has proposed to sum all these ints, but in this case, we don't need to swap_in_place and the count. With swap approach, we can count at the same time as we do the conversion, so no need to swap in place. Can somene help me to identify a real use case on which the swap_in_place can be used to reveive a message, without needing to do any additional copy from the swapped buffer to native data? Thanks, _____________________ Vicente Juan Botet Escribá http://viboes.blogspot.com/

Vicente Botet wrote: I'm looking for a use case where the use of swap_in_place (or whatever is renamed) is not followed/preceded by a copy. When I need to send a message I need to copy the information to send in a buffer. I gues that in this case the use of swap (copy) is the function to use. Can somene help me to identify a real use case on which the swap_in_place can be used to send a message that do not need to be initialized before sending? When I receive a message, I will need to store some of the messages information on application context, store them on local variables or pass them to other functions. All this suppose a copy from the buffer to the different kinds of native storage. I gues that swap (copy) should be used in this case also. The example of Terry reveives a array of ints and makes a swap_in_place, but do nothing with. Someone has proposed to sum all these ints, but in this case, we don't need to swap_in_place and the count. With swap approach, we can count at the same time as we do the conversion, so no need to swap in place. Can somene help me to identify a real use case on which the swap_in_place can be used to reveive a message, without needing to do any additional copy from the swapped buffer to native data? Terry replied: Yes. Image/video decompression. In these cases, each video frame is stored on a physical medium or is sent streaming across a network. The image is usually represented as a matrix of "coefficients" that are in either big- or little-endian format. During the decompression, the coefficients may be read several times, so it is beneficial to store these coefficients in native format in memory. Doing computation in place and transforming data is also quite common in signal-processing, e.g. the Fourier transform. Doing computation in place also provide a performance advantage because of memory caching. That said though, such high-performance applications usually involve (for me) exploitation of the underlying hardware and processor instruction set for the performance critical parts, and therefore, don't fall in the realm of generic C++ implementation. But... these applications usually also eventually involve some form or error-correction and/or compression close the the communication/storage layer. Once that happens, then the data is necessarily copied to another format. Frequently, these operations access blocks of the input stream and cannot be done in place (an in-place decompression algorithm doesn't make much sense). Once you need to do the copy, the advantage of in-place-conversion is lost. terry

vicente.botet wrote:
Hi,
I'm looking for a use case where the use of swap_in_place (or whatever is renamed) is not followed/preceded by a copy.
<snip>
Can somene help me to identify a real use case on which the swap_in_place can be used to reveive a message, without needing to do any additional copy from the swapped buffer to native data?
Thanks, _____________________ Vicente Juan Botet Escribá http://viboes.blogspot.com/
Hello Vicente - I hope you are doing well. It was a pleasure to meet you at boostcon. I think one problem might be the focus on "messaging" as the reason for endian swapping. Granted, that is a large use case and one that I suspect most of us use. I also do a fair amount of swapping of bytes/bits in signal processing work. Typically I have received some signal via a DMA transfer and now need to operate on it. As much as possible this is done in-place. Typical operations include changing the endian to match the processor. For example, many PCM codecs will result in a little endian audio signal; however, most of my favorite processors are big endian. The swap will be in-place. Another typical operation is time decimation for a Fourier transform which is basically bit-reversal of the indexes. This is also in-place. Even my messaging for these small embedded processors is in-place. I just don't have the memory nor cycles to make copies. A message is formed in memory. It is "transformed" to the right endian and then the buffer is sent to a DMA engine. I could provide dozens of use-cases of in-place endian transforms. Just start thinking little to no memory and not a lot of processor cycles and you can come up with a bunch. Hope this helps a little. The endian library is of great interest to me. I'm reading all of the email traffic but don't have the time right yet to jump into the discussion. michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

----- Original Message ----- From: "Michael Caisse" <boost@objectmodelingdesigns.com> To: <boost@lists.boost.org> Sent: Friday, June 04, 2010 8:37 PM Subject: Re: [boost] [endian] swap_in_place use case vicente.botet wrote:
Hi,
I'm looking for a use case where the use of swap_in_place (or whatever is renamed) is not followed/preceded by a copy.
<snip>
Can somene help me to identify a real use case on which the swap_in_place can be used to reveive a message, without needing to do any additional copy from the swapped buffer to native data?
Hello Vicente - I hope you are doing well. It was a pleasure to meet you at boostcon. I think one problem might be the focus on "messaging" as the reason for endian swapping. Granted, that is a large use case and one that I suspect most of us use. I also do a fair amount of swapping of bytes/bits in signal processing work. Typically I have received some signal via a DMA transfer and now need to operate on it. As much as possible this is done in-place. Typical operations include changing the endian to match the processor. For example, many PCM codecs will result in a little endian audio signal; however, most of my favorite processors are big endian. The swap will be in-place. Another typical operation is time decimation for a Fourier transform which is basically bit-reversal of the indexes. This is also in-place. Even my messaging for these small embedded processors is in-place. I just don't have the memory nor cycles to make copies. A message is formed in memory. It is "transformed" to the right endian and then the buffer is sent to a DMA engine. I could provide dozens of use-cases of in-place endian transforms. Just start thinking little to no memory and not a lot of processor cycles and you can come up with a bunch. Hope this helps a little. The endian library is of great interest to me. I'm reading all of the email traffic but don't have the time right yet to jump into the discussion. michael ______________________________________________ Hi Michael, thanks for all your use cases. Your use cases and the ones of Dave Handley help a lot. I see swap_in_place could be inevitable in some cases in particular when receiving some information. It is less the case for sending information. As you say "A message is formed in memory. It is 'transformed' to the right endian and then the buffer is sent to a DMA engine". The key here is the message is "formed in memory". I guess we can "form in memory" with the correct endianess, and avoid the swap. Anyway. swap_in_place is needed. This was just what I was looking to answer. Thanks, Vicente (Ah it was a pleasure to me too).
participants (3)
-
Michael Caisse
-
Terry Golubiewski
-
vicente.botet