Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #12835
| From | XeCycle <xecycle@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: vector as a char buffer ? |
| References | <xn0hncrwwbo878g000@news.astraweb.com> |
| Date | 2011-12-28 12:27 +0800 |
| Message-ID | <87r4zp9v7d.fsf@gmail.com> (permalink) |
| Organization | X-Privat.Org NNTP Server - http://www.x-privat.org |
"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
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