Description
ERealloc() is used to change the size of an allocated block.
Call Signature
any ptr ERealloc ( identifier type_name, int elements, any ptr old_ptr )
Return Value
any ptr
Pointer to the reallocated memory block.
Arguments
identifier type_name:
The name of the type of data to be allocated. This can be any basic type, or user defined type.
int elements:
The number of the above items to allocate.
any ptr old_ptr:
The data ptr being passed in.
Remarks
The resulting pointer may be assigned to a pointer variable. The memory block is re-allocated with the C routine HRealloc(). This is performed by allocating a new block of the desired size, copying the data from the old memory block, and then freeing the old memory block.
ERealloc() should not be used to allocate additional objects, nor to allocate structures that contain string or mstring fields.
Example
The following logic will loop over a large set of image values and increment the count for each pixel value in a histogram array. If the image value is larger than the histogram, the histogram is made larger, and the additional space is set to zero.
local int ptr Histogram, int HistSize, int NewSize, int i, int j
...
HistSize = 100
Histogram = EAlloc(int,HistSize)
for i = 1 to DBPixels(file_spec)
if( ImgValue[i] > HistSize )then
NewSize = ImgValue[i]
Histogram = ERealloc(int,NewSize,Histogram)
for j = HistSize + 1 to NewSize
Histogram[j] = 0
endfor
endif
Histogram[ImgValue[i]] = Histogram[ImgValue[i]] + 1
endfor
See also
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.