Does CString;;GetBufferSetLength Set/Allocate the CString Buffer
-
Hi I found the source of problem the exception occurred when I did CAsncSocket::Receive(CString*,int) I has previously done a GetBufferSetLength to a large enough size so I don't understand why I got an exception
-
Hi I found the source of problem the exception occurred when I did CAsncSocket::Receive(CString*,int) I has previously done a GetBufferSetLength to a large enough size so I don't understand why I got an exception
The
CString
class is not thread safe but usingCAsyncSocket
indicates that you are using multiple threads. When usingGetBuffer[Xxx]
, the string object is locked untilReleaseBuffer
is called (which must be called from the same thread). As Richard already noted, you need a byte buffer. While this can be achieved by usingCStringA
, I recommend to rethink your design. Don't use string classes for binary data and ensure thread safety. -
The
CString
class is not thread safe but usingCAsyncSocket
indicates that you are using multiple threads. When usingGetBuffer[Xxx]
, the string object is locked untilReleaseBuffer
is called (which must be called from the same thread). As Richard already noted, you need a byte buffer. While this can be achieved by usingCStringA
, I recommend to rethink your design. Don't use string classes for binary data and ensure thread safety. -
You probably don't need an array class if you just want to copy data and do not need inserting or removing of items. If you know the (max.) size in advance just use a plain array allocated with
new
. If not, you can still grow by allocating a new array, copying data from the old, and delete the old.CByteArray
is also an MFC class which is probably also not thread safe. But it is impossible to help without knowing what your code is doing. The question are (you may ask and solve them yourself): Does my array require special modification functions besides copying? Which functions use my array under which conditions (read only, write only, both)? Where is may array allocated (this might be at different code points if resizing is necessary)? Where it is deleted? Do I need thread safety?