setup the map how you are plus the current width and height...
unsigned int MapWidth = 0, MapHeight = 0;struct MapFormat ** Map = 0; // except now we have to malloc this array!
then to resize the map you can use this function:
void SetMapSize( unsigned int _Width, unsigned int _Height ){ unsigned int i; if( Map == 0 ) { // create original memory Map = ( void * )malloc( sizeof( void * ) * _Width ); for( i = 0; i < _Width; i++ ) Map = malloc( <span class="cpp-keyword">sizeof</span>( <span class="cpp-keyword">struct</span> MapFormat ) * _Height );<br> }<br> <span class="cpp-keyword">else</span><br> {<br> <span class="cpp-comment">// chop off the extra width if the width is set smaller!</span><br> <span class="cpp-keyword">for</span>( i = _Width; i < MapWidth; i++ )<br> free( Map );<br><br> <span class="cpp-comment">// resize width of the map</span><br> Map = realloc( Map, <span class="cpp-keyword">sizeof</span>( <span class="cpp-keyword">void</span> * ) * _Width );<br> <br> <span class="cpp-comment">// add extra width if the width was set larger!</span><br> <span class="cpp-keyword">for</span>( i = MapWidth; i < _Width; i++ )<br> Map = malloc( <span class="cpp-keyword">sizeof</span>( <span class="cpp-keyword">struct</span> MapFormat ) * _Height );<br> <br> <span class="cpp-comment">// resize the old height</span><br> <span class="cpp-keyword">if</span>( _Height != MapHeight )<br> <span class="cpp-keyword">for</span>( i = <span class="cpp-number">0</span>; i < ( _Width < MapWidth ? _Width : MapWidth ); i++ )<br> Map = realloc( Map, <span class="cpp-keyword">sizeof</span>( <span class="cpp-keyword">struct</span> MapFormat ) * _Height );<br> }<br> MapWidth = _Width;<br> MapHeight = _Height;<br>}<br><br></pre></div><!–ENDSCRIPT–><br><br><br>then when you're ending your program don't forget to destroy the allocated memory!!<br><br><!–STARTSCRIPT–><!–source lang="c"–><div class="source"><pre><br><span class="cpp-keyword">void</span> DestroyMap()<br>{<br> <span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">int</span> i;<br> <span class="cpp-keyword">for</span>( i = <span class="cpp-number">0</span>; i < MapWidth; i++ )<br> free( Map );<br> free( Map );<br> Map = <span class="cpp-number">0</span>;<br>}<br><br></pre></div><!–ENDSCRIPT–><br><br>