If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: allocating bidimensional matrix

Well just for fun I decided to fix your reallocating issue and give you a few pointers ( hopefully valid ) First of all you have no need of the static variable and no need to save the length of strings because what you are reallocating is just an array of pointers to the malloced strings, you dont need to reallocate the strings just the array of pointers so all you need to save is count of elements inside which you already use the n parameter for :P Second mistake you have was the dereferencing of the list pointer , *list[n] which in fact dereferences list[n] but you actually need to dereference list and get its n-th element so a pair of brackets can be very useful here (*list)[n]. So the final code should look like this:

Re: allocating bidimensional matrix

There we go fixed in previous post for your viewing pleasure
I just fixed it because he wanted to see how it would look while using realloc and his original snippet didnt bother with freeing memory, and 'huge' is quite an overstatement there.

Re: allocating bidimensional matrix

Originally Posted by Lindley

Just for fun: realloc() can be used in place of free() by specifying a new size of 0.

cool XD well I learned a lot of things from this discussion and I think I don't want to see more than ONE star before a variable for a while XD
personally I hate working with dyn mem because I ever feel there's some leak somewhere...
the realloc for the string has been made because at the beginning I wanted to make an insert possible but (unfortunately / fortunately) std::vector.insert() took all the fun away XD

about my last post I solved declaring a support single var and "push_back"ed it into a support vector and then "push_back"ed the vector in the matrix...
std::vector make me feel much quiet about memory :P