(Owed by: Spring Night rain Http://blog.csdn.net/chunyexiyu reprint please indicate the source)
If you call a function in a DLL and use a vector to pass a parameter, error "vector size exception, length overrun " code location " _throw(length_error,"vector<t> too Long") "
Then you may have encountered vector debug version and release version mismatch problem.
In the case of non-conditional compilation, if :
1. The calling program uses the debug version of the vector
2. use release version vector in Dll
Then pass the empty vector, this problem will occur ( of course, the transfer of non-empty vectors should also be problematic )
The problem arises because :
The debug version of the STL in VS is different from the release version vector in memory allocation, resulting in inconsistent data structures on both sides. A memory overflow-related issue occurred while assigning a value. It is mistaken for the vector length overrun problem.
A detailed reason for the problem can be seen by looking at the code of vector in VS :
1. Vector inherits from _vector_val typedef _vector_val<_ty, _ax> _mybase; Explicit vector (const _alloc& _al) : _mybase (_al) 2. _vector_val inherits from _container_base_aux_alloc _vector_val (_alloc _al = _alloc ()) : _container_base_aux_alloc<_alloc> (_al), _alval (_al) 3. Follow-up See, at Debug and release, the separate branches are gone #if!_has_iterator_debugging && (defined (_DEBUG) | | _secure_scl) //We have an Aux object. #define _CONTAINER_BASE_AUX_ALLOC _container_base_aux_alloc_real #else //We have an Aux object. #define _CONTAINER_BASE_AUX_ALLOC _container_base_aux_alloc_empty #endif in _container_base_aux_alloc_real ( inherited from _container_base_aux), there is a variable _aux_cont * _myownedaux; But there is no such variable in _container_base_aux_alloc_empty ( inherited from _container_base). To view the macro definition: #if!defined (_has_iterator_debugging) #if defined (_DEBUG) #define _HAS_ITERATOR_DEBUGGING 1/* for range checks, etc. */ #else #define _has_iterator_debugging 0 #endif/* Defined (_DEBUG) */ #else #if!defined (_DEBUG) && _has_iterator_debugging! = 0 #include <crtwrn.h> #pragma _crt_warning (_no_iterator_debugging) #undef _has_iterator_debugging #define _has_iterator_debugging 0 #endif #endif/*!defined (_has_iterator_debugging) */ #if!defined (_SECURE_SCL) #define _SECURE_SCL 1 #endif When I debug this side I see: Release version went the branch _container_base_aux_alloc_real. DEUBG version went the branch _container_base_aux_alloc_empty. |
As can be seen from the above, this is actually very much related to the STL implementation in VS, and the correlation of the debug mechanism in VS, which makes the debug/release version of the data structure is different.
(Owed by: Spring Night rain Http://blog.csdn.net/chunyexiyu reprint please indicate the source)
Std::vector Pass DLL parameter exception-length overrun