_CEE_REALLOC_CONTROL

_CEE_REALLOC_CONTROL has two parameters. The first parameter specifies the lower bound for the tolerance percentage to be applied. This variable reflects the number of bytes that will cause the realloc() control feature to be activated. For instance, if an application issues a malloc() to request storage and a subsequent realloc() to change the size of that storage allocation, this parameter determines whether the request will be increased - with the intent that subsequent reallocations will not require additional storage be obtained and data copied.

The second parameter specifies the percentage that the storage request will be increased if the request is greater than or equal to the lower bound specified in the first parameter.

The format of the environment variable is:
 _CEE_REALLOC_CONTROL=bound,percentage
bound
a, aK, ak, in which a is an integer.
percentage
p, which is an integer between 0 and 100. The default value is 0, which means that this feature is not in use.

Attempting to reallocate storage to a new size of near 2GB while this environment variable is set may cause realloc() to report that a negative new size was provided as input.

Note: The following examples use storage sizes that are for illustration purposes only. The sizes are examples and do not reflect any storage rounding that might occur.
The following example shows this control feature being used within a loop and how an allocation of a new storage element can be eliminated:
 _CEE_ REALLOC_CONTROL=100,20
/* an example in C*/
char * buffer;
size_t buffsize;
Int i;
buffsize = 100; 
buffer = malloc(buffsize);  

for ( i = 0; i <= 2; ++i ) {
buffsize += 10; 
buffer = realloc(buffer,buffsize); 
}

for ( i = 0; i <= 2; ++i ) { 
buffsize -= 10; 
buffer = realloc(buffer,buffsize);
}                                                                               
Because the realloc() request is greater than the lower bound, the first pass through the first loop results in a new buffer with the same contents as before but within a storage element of size 132 (110+(110*.20)) and buffsize=110. All the data in the first buffer (100 bytes) is copied to the second (new) buffer.

The second and third pass through the first loop issue the same realloc, but result in no action being taken because the new buffsize of 120 and then 130 allows the requested storage to remain within the current allocation of 132 bytes, even if both requests are greater than the lower bound. Therefore, allocation of new storage elements and copies of data are eliminated.

Additionally, the first two paths through the second loop also result in no action because they result in a buffsize less than the current allocation and can also fit within the current allocation.

The last path through the second loop results in a new buffer of buffsize 100. Although this request is also less than the current allocation and fits in the current allocation, the assumption is that no tolerance ever occurred because the requested size plus the increase have resulted in a storage allocation less than the current allocation.

In other words, if realloc control feature is relevant (the requested storage allocation is greater than the lower bound), the rules are: