Boost logo

Boost Users :

Subject: Re: [Boost-users] Transferring files across a network - general question to all on sizeof(Boost.Array)
From: Cliff Green (cliffg_at_[hidden])
Date: 2009-01-16 11:35:17


>I hope attached files will help you. This is a client that can send files to server. I got this example from Boris and it is working at my side.

Thanks, Rahul and Boris (for original code) - that should help Andrew!

One question, though (and this is to the general list, not just Rahul and Boris) - in client.cpp there's the following code:

boost::array<char, 4096> buffer;
...
std::size_t size = std::min(sizeof(buffer), file.size() - sent);

The above line assumes that the size of a boost::array object is the size of the internal char buffer - I'm not sure this is a good assumption (it assumes zero space overhead for boost::array, which might be the case in the implementation, but seems dangerous - I don't see this documented or guaranteed anywhere in the boost::array docs, plus there's always the possibility of compiler added padding). I would think better and safer (and guaranteed to be correct by boost::array) is:

std::size_t size = std::min(buffer.size(), file.size() - sent);

HTH,

Cliff



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net