A problem about STL(string and vector)

Firstly I define a struct with a stl(string) member like here:
typedef struct _UdpClient{
    int fd;
    fd_set rset;
    string ip;
    unsigned short port;
}UdpClient;


then, I use vector<UdpClient> variable para assignment in a fuction(stack), when this function is called frequently by other, this program will core. such as:
void UdpImp::UdpSend(...)
{
    ...
    vector<UdpClient> vUdpClient = m_Comm.vUdpClient;
    ...
}


core reason:
#0 0xb7d42e21 in memcpy () from /lib/libc.so.6
#1 0xb7ed8be4 in std::string::_Rep::_M_clone () from /usr/lib/libstdc++.so.6
#2 0xb7ed9507 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string ()
from /usr/lib/libstdc++.so.6
#3 0x080ccfe4 in _UdpClient (this=0xaf6254fc) at UdpImp.h:125
#4 0x080cd065 in std::_Construct<_UdpClient, _UdpClient> (__p=0xaf6254fc, __value=@0x84ddcec)
at /usr/include/c++/4.1.2/bits/stl_construct.h:81
#5 0x080cd0bd in std::__uninitialized_copy_aux<__gnu_cxx::__normal_iterator<_UdpClient const*, std::vector<_UdpClient, std::allocator<_UdpClient> > >, _UdpClient*> (__first={_M_current = 0x84ddcec}, __last={_M_current = 0x84dde24}, __result=0xaf625460)
at /usr/include/c++/4.1.2/bits/stl_uninitialized.h:86
#6 0x080cd15b in std::uninitialized_copy<__gnu_cxx::__normal_iterator<_UdpClient const*, std::vector<_UdpClient, std::allocator<_UdpClient> > >, _UdpClient*> (__first={_M_current = 0x84ddc50}, __last={_M_current = 0x84dde24}, __result=0xaf625460)
at /usr/include/c++/4.1.2/bits/stl_uninitialized.h:113
#7 0x080cd17d in std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<_UdpClient const*, std::vector<_UdpClient, std::allocator<_UdpClient> > >, _UdpClient*, _UdpClient> (__first={_M_current = 0x84ddc50}, __last={_M_current = 0x84dde24}, __result=0xaf625460)
at /usr/include/c++/4.1.2/bits/stl_uninitialized.h:254
#8 0x080cd263 in vector (this=0xac03de54, __x=@0x84d6dd0) at /usr/include/c++/4.1.2/bits/stl_vector.h:234
#9 0x080b690d in UdpImp::UdpSend (this=0x84d6d50, szSendBuf=0x84dfae8 "", iSendBufSize=149, sIp=@0xac03dffc,
uPort=@0xac03e002) at :1226

Who tell me Why, tks!

There's no way anyone could figure it out from ten lines of code and a stack trace.

Try running the program through Valgrind. See if that tells you anything.
Topic archived. No new replies allowed.