Boost logo

Boost :

From: Rene Rivera (grafik666_at_[hidden])
Date: 2002-03-19 01:13:17

On 2002-03-19 at 04:37 PM, dylan_nicholson_at_[hidden] (Dylan Nicholson)

>If we definitely decide to put in a "copy_file" routine into
>then believe it or not, the following single line of code is remarkably
>efficient (at least under HP aCC 3.33, which is what I tested it with):
>bool copy(const char* src, const char* dest)
> return std::ofstream(dest) << std::ifstream(src).rdbuf();
>The following is almost twice as slow (!):
>bool copy2(const char* src, const char* dest)
> std::ifstream ifs(src);
> ifs.seekg(0, std::ios_base::end);
> std::vector<char> buf(ifs.tellg());
> ifs.seekg(0, std::ios_base::beg);
> return[0], buf.size()) &&
> std::ofstream(dest).write(&buf[0], buf.size());
>I tested this copying a local ~200Kb file 50 times, so I don't know how
>representative that is. All sorts of factors might be at play, but the
>were consistent.

OK, how can you say "remarkably efficient" when you don't give us numbers, and
you only compare two methods. How about comparing it to other methods like
cstdio, raw io, or even (on some platforms) memory mapped files?

-- grafik - Don't Assume Anything
-- rrivera_at_[hidden] - grafik_at_[hidden]
-- 102708583_at_icq - Grafik666_at_AIM - Grafik_at_[hidden]

Boost list run by bdawes at, gregod at, cpdaniel at, john at