Re: Thread deadlock misery



Ben Voigt wrote:

std::vector< char > buffer( pATFP->TFP.size );
WSABUF wsaBuf = { pATFP->TFP.size, &buffer.front() };


I don't know if that's guaranteed to be contiguous memory

Stroustrup suggests that it is contiguous. Interesting discussion here:
http://www.velocityreviews.com/forums/t281876-is-stdvector-contiguous.html

The original standard didn't explicitly state contiguity, but it has been corrected since then, and now it is an explicit guarantee. Besides, there is no known implementation of vector where memory is not contiguous.

, better to use:

std::auto_ptr buffer = new char[TFP.size];

This works with every compiler that I tried, but strictly speaking, it's not correct. auto_ptr calls delete, not delete [], and therefore it is not guaranteed to work. I personally use boost::scoped_array, it's extremely lightweight and is guaranteed to be correct:

boost::scoped_ptr<char> buffer(new char[size]);

I think its c'tor is explicit, you can't use assignment there.

Tom
.



Relevant Pages

  • Re: Thread deadlock misery
    ... I don't know if that's guaranteed to be contiguous memory ... The original standard didn't explicitly state contiguity, ... and now it is an explicit guarantee. ... I think its c'tor is explicit, ...
    (microsoft.public.vc.language)
  • Re: Accessing raw values in a vector
    ... > that the vector stores its data in contiguous memory, ... Practically speaking yes (although it is not yet in the norm, ... That, on the other hand, is wrong: there is no guarantee than a vector ... iterator can be used as a pointer: You can use &MyVectto get a pointer ...
    (microsoft.public.dotnet.languages.vc)
  • Re: WaitForSingleObject() will not deadlock
    ... POSIX itself makes no guarantee, ... That said, I do hope to find a stronger (ie, explicit) lack of guarantee. ... While I did assert that POSIX semaphores are in fact not fenced, ...
    (microsoft.public.vc.mfc)
  • Re: WaitForSingleObject() will not deadlock
    ... I will continue to look, as time permits, but I'm not confident that ... POSIX itself makes no guarantee, ... That said, I do hope to find a stronger (ie, explicit) lack of guarantee. ...
    (microsoft.public.vc.mfc)

Loading