Article View: alt.comp.lang.learn.c-c++
Article #368Re: Re-dimension arrays
From: Nick Ambrose
Date: Tue, 29 Jun 1999 00:00
Date: Tue, 29 Jun 1999 00:00
25 lines
1540 bytes
1540 bytes
Magnus Hult wrote: > Hi there, > > is there anyway to redimension an array without deleting stuff that's > already in it (something like VB's "ReDim Preserve")? > > I know it's possible to do this: > int array[1]; > array[17] = 1234; > but can I be sure no important data are being overwritten? > It's possible to do this, it's also undefined behavior (you are writing into random memory off the end of your aray). The easiest way of achieving this is to look at the container std::vector which is supposed to act like a resizable array (or if you are doing lots of numerical work, std::valarrray might be more useful) otherwise, you may have to allocate a bigger array using new [] and copy all the old elements across and delete the first array. Nick
Technical Details
Message-ID:
<37795EF9.1C244E48@interdyn.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<WUbe3.540$nZ5.877@nntpserver.swip.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,51beb6ad66d52548,start X-Google-Attributes: gidf8d38,public X-Google-Thread: 114592,51beb6ad66d52548,start X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,51beb6ad66d52548,start X-Google-Attributes: gid109fba,public From: Nick Ambrose <nicka@interdyn.com> Subject: Re: Re-dimension arrays Date: 1999/06/29 Message-ID: <37795EF9.1C244E48@interdyn.com> X-Deja-AN: 495405296 Content-Transfer-Encoding: 7bit References: <WUbe3.540$nZ5.877@nntpserver.swip.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: DigiLink Network Services Mime-Version: 1.0 Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++