Thread: resize array of pointers and save

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    161

    resize array of pointers and save

    I have declared a pointer to a pointer(char ** pointer. I can resize an array of pointers now. But how do I pas on the position of where all the pointers are pointing to? I know one way, have a loop and and save everything to a temp pointer then free the memory and allocate more memory. Then have another loop and reasign everything one by one. Is there a faster way or less memory consumming way?

    Thanx in advance!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Allocate the new array
    Copy your old array to your new array
    Delete the old array

    Or use an expanding data structure from the STL which takes care of this for you, such as list and vector.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of pointers
    By totalnewbie in forum C Programming
    Replies: 7
    Last Post: 12-07-2008, 03:23 PM
  2. Reading a file into an array for fast access later
    By matsharp in forum C Programming
    Replies: 10
    Last Post: 08-03-2006, 02:42 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM