Главная страница | назад





Article #15388: Pseudo-code to show use of realloc and farrealloc

 Question and Answer Database
FAQ388C.txt Pseudo-code to show use of realloc and farrealloc
Category :C/C++ Language Issues
Platform :All
Product :BC++ 5.x
Question:
Pseudo-code for realloc and farrealloc to show how it works:
Answer:
void _far *farrealloc(void _far *old_ptr, unsigned long new_size)
{
unsigned long old_size = look up old size in allocation records
void _far *new_ptr = NULL;
if (new_size <= old_size)
{
shrink the memory block
new_ptr = old_ptr
}
else if (current memory block cannot be expanded)
{
allocate a new block, storing address in new_ptr
copy old_size bytes from array starting at old_ptr to
the one starting at new_ptr
do nothing with the extra (new) memory at the end
free old_ptr
}
else if (current memory block can be expanded)
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99