Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #12828

Re: vector as a char buffer ?

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: vector as a char buffer ?
Date 2011-12-27 09:04 -0500
Organization A noiseless patient Spider
Message-ID <jdcj91$eaa$1@dont-email.me> (permalink)
References <xn0hncrwwbo878g000@news.astraweb.com>

Show all headers | View raw


On 12/27/2011 8:26 AM, Asger Joergensen wrote:
> I'm not that used to the stl so I ask to be on the safe side:
>
> typedef std::vector<char>  TMembuf;
>
> TMembuf buf(1000);
> char* p =&buf[0];
>
> I have tested it and it seem to work fine just like:
>
> char* p = new char[1000];
>
> and without the delete[];
>
> But is there any downside to doing like this ?

Not really.  Just remember that 'p' is not owned by you and that its 
validity is tightly linked to the lifetime of 'buf'.

V
-- 
I do not respond to top-posted replies, please don't ask

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

vector as a char buffer ? "Asger Joergensen" <Junk@Asger-P.dk> - 2011-12-27 13:26 +0000
  Re: vector as a char buffer ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-27 09:04 -0500
    Re: vector as a char buffer ? "Asger Joergensen" <Junk@Asger-P.dk> - 2011-12-27 20:25 +0000
    Re: vector as a char buffer ? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-12-27 21:05 +0000
  Re: vector as a char buffer ? XeCycle <xecycle@gmail.com> - 2011-12-28 12:27 +0800
    Re: vector as a char buffer ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-28 08:56 -0500

csiph-web