This message was edited by stober at 2005-4-8 7:21:26
: i thought i can use realloc only with sizes larger than the actual size. is this wrong?
: would be nice...
Yes, that is wrong.
realloc() can be used to shrink the allocation too, but that doesn't mean the program will gain more memory. It only means that the difference is now available to allocation by something else. malloc() and realloc() only work with contiguous memory locations, and most operating systems do not attempt to defragment memory unless there are two more adjacent free memory blocks.
So reducing the size of allocated arrays may, or may not, give your program more memory. There's a lot of ifs, ands and buts.