resize array of pointers and save

This is a discussion on resize array of pointers and save within the C++ Programming forums, part of the General Programming Boards category; I have declared a pointer to a pointer(char ** pointer . I can resize an array of pointers now. But ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 09:33 AM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21