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


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

Re: vector as a char buffer ?

From XeCycle <xecycle@gmail.com>
Newsgroups comp.lang.c++
Subject Re: vector as a char buffer ?
References <xn0hncrwwbo878g000@news.astraweb.com>
Date Wed, 28 Dec 2011 12:27:50 +0800
Message-ID <87r4zp9v7d.fsf@gmail.com> (permalink)
User-Agent Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux)
Cancel-Lock sha1:Kd+LoB4Aby5S3s9Ab/hGwyzHewo=
MIME-Version 1.0
Content-Type text/plain
NNTP-Posting-Host $$5lonjgdxpj7l67.news.x-privat.org
Organization X-Privat.Org NNTP Server - http://www.x-privat.org
Lines 33
X-Authenticated-User $$1tz_xxnxz085nc1qk
X-Complaints-To abuse@x-privat.org
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!newsfeed.x-privat.org!x-privat.org!not-for-mail
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:12835

Show key headers only | View raw


"Asger Joergensen" <Junk@Asger-P.dk> writes:

> Hi

Hello,

> 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 ?

This is not recommended, of course.  You didn't even use any of
the vector facilities, in this case.  Vectors provide the method
reserve().

However if you want a buffer, there's circular buffer in boost
library.

-- 
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

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