Hi,
i have declared an array of class point.
point buffer[100];
but somewhere during my program, it is known that the size is smaller, says size 50.
how do i reduce the size of the buffer from there?
Thanks in advance!!
Hi,
i have declared an array of class point.
point buffer[100];
but somewhere during my program, it is known that the size is smaller, says size 50.
how do i reduce the size of the buffer from there?
Thanks in advance!!
C doesn't allow you to do that. Nor does C++. What you could do is dynamically allocate an array, put what you want in it, then when you get the size you want, transfer that data to a newly allocated array of the appropriate size and delete the old one.
Sent from my iPadŽ
SlyMaelstrom is right, that's the way to do it. But be aware that the technique he describes may fragment the heap and by doing so you might in practice end up with smaller free memory blocks in your heap which may have the effect that you can not allocate a memory block of a given size larger than the largest free block, even though the total amount of free memory is more than the block you try to allocate. That is if you don't use techniques such as handles (for example a char**) and use memory related functions for compacting the heap. Maby you should consider trying to do what SlyMaelstrom suggested only when you are out-of-memory.