Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: How to get the functionality of realloc() in C++ ? Message-ID: <728@taumet.com> Date: 14 May 91 22:01:25 GMT References: <1991May13.191807.29295@csl.dl.nec.com> Organization: Taumetric Corporation, San Diego Lines: 20 manohar@csl.dl.nec.com (Mun o her) writes: >How to get the functionality of 'realloc()' in C++ ? >Note : realloc() is used to change the size of the memory. C++ does not support the functionality of realloc() via 'new' and 'delete'. You have two choices: 1. Do it by hand. Use 'new' to acquire a larger space, copy the data, and 'delete' the old space. This is what realloc() does anyway, if the space cannot be extended where it is. 2. Use malloc(), realloc(), and free() in your C++ program. Check your documentation to see whether this is supported. It probably is. WARNINGS: Do not use malloc/realloc for objects with constructors. Do not 'delete' something allocated with malloc/realloc. Do not 'free' something allocated with 'new'. -- Steve Clamage, TauMetric Corp, steve@taumet.com