syncman wrote in news:cc9cc476.0401201137.6e8c264b@posting.google.c om:
[color=blue]
> I want to do a lot of data manipulation and passing. The buffer I
> have always used before STL was a simple char buf[SIZE] .
>
> I can pass its address easily.
> void f (char *buf)[/color]
You could pass it safer as
void f( char (&buf)[ SIZE ] )
assuming SIZE is a compile-time const.
[color=blue]
>
> I can assign to its middle with a moving pointer.
> myStruct *p = (myStruct *) buf; // Cast
> *p++ = myValue;
>[/color]
This requires that myStruct has the same alignment requirments
as a char (i.e. no alignment requirments :), you'll get away
with it many platforms but *not* all.
[color=blue]
> etc
>
> Should I be using a vector<char> or something? I know that it would
> provide better type safety (no cast), and would catch overruns. Also,
> it would grow as needed, but I don't need that here because I know the
> size beforehand. Is it slower? Any other considerations?
>
> Can you say that there is NO reason why anyone should use char[]
> instead of vector<char>?
>[/color]
You should be using an array or vector of myStruct. Use an array (*)
if your size is a constant and you can resonably define this array
as a local variable, otherwise use std::vector< myStruct >.
(*) also checkout boost::array<> as an alternative to inbuilt
array's this will give you an STL interface, so it can easily be
changed to std::vector if the need arises.
http://www.boost.org/libs/array/array.html
Rob.
--
http://www.victim-prime.dsl.pipex.com/