dealloc + %alloc() 与 %realloc() - RPGLE

dealloc + %alloc() vs %realloc() - RPGLE

知道 ptr <> *null, 这两段代码在功能上是相同的吗?

dealloc(en) ptr;
ptr = %alloc(500);

ptr = %realloc(ptr:500);

没有

%realloc()保存ptr指向的存储的当前值

因此,如果没有足够的 space 来扩大现有的 space,从而为 ptr 返回相同的值。系统会将字节从原来的space复制到新的space.

来自手册:
%REALLOC (Reallocate Storage)

The heap storage pointed to by the returned pointer has the same value as the heap storage pointed to by ptr. If the new length is longer than the old length, the additional storage is uninitialized.