Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. resize multiple dimensional vector array in while loop

resize multiple dimensional vector array in while loop

Scheduled Pinned Locked Moved ATL / WTL / STL
graphicsdata-structurestestingbeta-testingperformance
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cy163 hotmail com
    wrote on last edited by
    #1

    Hi ALL, outside a while loop, I declare a 3-D vector array

    vector Psodu;
    Psodu.reserve(10);
    
    vector > > structPersonVar(2, vector >(2,Psodu));
    

    in the while loop, i have to change the size of the array in every iteration. First, I use the following code to release the memory for(int j=0; j < 2; j++) { for(int k =0; k < 2; k++) { vector().swap(structPersonVar[j][k]); } vector >().swap(structPersonVar[j]); } vector > >().swap(structPersonVar); Then, I resize the array

    structPersonVar.resize(20);
    for(j=0; j < 12; j++)
    {
    	structPersonVar\[j\].resize(2);
    	for(int k =0; k < 2; k++)
    	{
    		structPersonVar\[j\]\[k\].reserve(10);	
    	}
    }
    

    I am not very sure whether i am correct by doing in this way,though it works fine with testing program.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups