Swap allocator problem in multi_array.hpp
When resizing a multi-dimensional array I receive the warning:
d:\microsoft visual studio\vc98\include\xutility(100) : warning C4101:
'_Tmp' : unreferenced local variable
d:\boost\include\boost-1_31\boost\multi_array.hpp(246) : see
reference to function template instantiation 'void __cdecl
std::swap(class std::allocator<double> &,class std::allocator<double>
&)' being compiled
An unreference local variable is not exactly the end of the world, but
it is churned out every time a file is compiled that include this
function and I'd rather not disable this warning. I can find no mention
of anyone else having this problem for such a widely used function
(dynamically resizing arrays).
The specific line that appears to be causing the problem is:
swap(this->allocator_,new_array.allocator_);
in "multi_array.hpp"
I am resizing the array like so
header file:
typedef boost::multi_array
Hello Ewan, On Oct 14, 2004, at 11:04 AM, Ewan Campbell wrote:
When resizing a multi-dimensional array I receive the warning:
d:\microsoft visual studio\vc98\include\xutility(100) : warning C4101: '_Tmp' : unreferenced local variable d:\boost\include\boost-1_31\boost\multi_array.hpp(246) : see reference to function template instantiation 'void __cdecl std::swap(class std::allocator<double> &,class std::allocator<double> &)' being compiled Hmm...this looks like the warning is pointing at the implementation of swap in your compiler's standard library.
If I initalising the array to shape and then resize it there is no problem, but I require it to be a class member variable.
what exactly do you mean by "initialiing the array to shape and then resize it"? Can you show a complete piece of code that gives the warning and a complete piece of code that does not but still uses resize? Thanks, ron
When resizing a multi-dimensional array I receive the warning:
d:\microsoft visual studio\vc98\include\xutility(100) : warning C4101: '_Tmp' : unreferenced local variable d:\boost\include\boost-1_31\boost\multi_array.hpp(246) : see reference to function template instantiation 'void __cdecl std::swap(class std::allocator<double> &,class std::allocator<double> &)' being compiled
Hmm...this looks like the warning is pointing at the implementation of swap in your compiler's standard library.
If I initalising the array to shape and then resize it there is no problem, but I require it to be a class member variable.
what exactly do you mean by "initialiing the array to shape and then resize it"? Can you show a complete piece of code that gives the warning and a complete piece of code that does not but still uses resize?
Thanks,
ron
I appear to have made a small error, the warning occurs 'whenever' resize is called. So the problem now is: Every time the resize function of multi_array is called, a warning is generated in the use of MSVC++ 6.0's implementation of std::swap. The problem is solved by commenting out the line swap(this->allocator_,new_array.allocator_); in multi_array.hpp This hasn't incurred an execution problem under debug or release. Could someone explain this? What is the purpose of this line, and why wasn't it swapping the allocators? Thanks, Ewan
On Oct 19, 2004, at 4:37 AM, Ewan Campbell wrote:
I appear to have made a small error, the warning occurs 'whenever' resize is called.
So the problem now is:
Every time the resize function of multi_array is called, a warning is generated in the use of MSVC++ 6.0's implementation of std::swap.
The problem is solved by commenting out the line swap(this->allocator_,new_array.allocator_); in multi_array.hpp
In general, I'd say this is a dangerous thing to do, particularly because I don't know how std::swap is implemented in your compiler. It seems like the compiler is complaining about an unused variable in the implementation, which does not mean that the allocators are not being swapped.
This hasn't incurred an execution problem under debug or release. Could someone explain this? What is the purpose of this line, and why wasn't it swapping the allocators?
The resize operation preserves as much of the contents of the original array as possible. To do so, it must allocate a new portion of memory and copy the salvageable elements to it. The algorithm essentially builds a new array of the right size and swaps the guts of the original array out. Hope that helps, ron
I appear to have made a small error, the warning occurs 'whenever' resize is called.
So the problem now is:
Every time the resize function of multi_array is called, a warning is generated in the use of MSVC++ 6.0's implementation of std::swap.
The problem is solved by commenting out the line swap(this->allocator_,new_array.allocator_); in multi_array.hpp
In general, I'd say this is a dangerous thing to do, particularly because I don't know how std::swap is implemented in your compiler. It seems like the compiler is complaining about an unused variable in the implementation, which does not mean that the allocators are not being swapped.
This hasn't incurred an execution problem under debug or release. Could someone explain this? What is the purpose of this line, and why wasn't it swapping the allocators?
The resize operation preserves as much of the contents of the original array as possible. To do so, it must allocate a new portion of memory and copy the salvageable elements to it. The algorithm essentially builds a new array of the right size and swaps the guts of the original array out.
The MSVC++ 6.0 compiler implements swap like so: template<class _Ty> inline void swap(_Ty& _X, _Ty& _Y) {_Ty _Tmp = _X; _X = _Y, _Y = _Tmp; } The unreferenced local variable warning is referring to _Tmp. Since _Tmp is required to swap the variables, does this not indicate that this particular use of the swap function is redundant? Thanks again, Ewan
Ewan Campbell wrote:
The MSVC++ 6.0 compiler implements swap like so:
template<class _Ty> inline void swap(_Ty& _X, _Ty& _Y) {_Ty _Tmp = _X; _X = _Y, _Y = _Tmp; }
The unreferenced local variable warning is referring to _Tmp. Since _Tmp is required to swap the variables, does this not indicate that this particular use of the swap function is redundant?
It may be redundant for a specific allocator type, but by commenting the swap() line you are eliminating the swap call for all possible allocator types, some of which may, indeed, need it.
At Wednesday 2004-10-20 04:57, you wrote:
I appear to have made a small error, the warning occurs 'whenever' resize is called.
So the problem now is:
Every time the resize function of multi_array is called, a warning is generated in the use of MSVC++ 6.0's implementation of std::swap.
The problem is solved by commenting out the line swap(this->allocator_,new_array.allocator_); in multi_array.hpp In general, I'd say this is a dangerous thing to do, particularly because I don't know how std::swap is implemented in your compiler. It seems like the compiler is complaining about an unused variable in the implementation, which does not mean that the allocators are not being swapped.
This hasn't incurred an execution problem under debug or release. Could someone explain this? What is the purpose of this line, and why wasn't it swapping the allocators?
The resize operation preserves as much of the contents of the original array as possible. To do so, it must allocate a new portion of memory and copy the salvageable elements to it. The algorithm essentially builds a new array of the right size and swaps the guts of the original array out.
The MSVC++ 6.0 compiler implements swap like so:
template<class _Ty> inline void swap(_Ty& _X, _Ty& _Y) {_Ty _Tmp = _X; _X = _Y, _Y = _Tmp; }
The unreferenced local variable warning is referring to _Tmp. Since _Tmp is required to swap the variables, does this not indicate that this particular use of the swap function is redundant?
Looks more to me like just one more bug in an old (and should be retired), out of date, and non-conformant compiler.
Thanks again, Ewan
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
participants (4)
-
Ewan Campbell
-
Peter Dimov
-
Ronald Garcia
-
Victor A. Wagner Jr.