Hi,
I'm a little confused about how to use dynamic sized arrays with alloc and realloc.
Consider the following code:
When I do the dsply it print 'Z'. If I reallocate the array for a dimension of 5 why it still prints the value of the position 100? When I debug th program it shows all the array positions.
However I found this site, where it states the following:
"It's important to remember that, while you are dynamically allocating memory for the array, you are not dynamically changing the number of elements in the array. The %ELEM function will still indicate 32767 elements throughout the entire process."
So my question is: does it really allocate/reallocate the memory, or nothing happened? How can I know for sure?
Thanks
I'm a little confused about how to use dynamic sized arrays with alloc and realloc.
Consider the following code:
Code:
D response s 10 D ptr s * inz(*Null) D array s 1 dim(32767) D based(ptr) * C eval ptr = %alloc(%size(array) * 10) C eval array(1) = 'A' C eval array(2) = 'B' C eval array(3) = 'C' C eval array(4) = 'D' C eval array(5) = 'F' C eval ptr = %realloc(ptr: %size(array) * 5) C eval array(100) = 'Z' C array(100) dsply response C dealloc(n) ptr C eval *inlr = *on C return
However I found this site, where it states the following:
"It's important to remember that, while you are dynamically allocating memory for the array, you are not dynamically changing the number of elements in the array. The %ELEM function will still indicate 32767 elements throughout the entire process."
So my question is: does it really allocate/reallocate the memory, or nothing happened? How can I know for sure?
Thanks
Comment