### _trealloc -- Reallocate Tiled Storage Block (OS/2)

Format

>     #include <stdlib.h>  /* also in <malloc.h> */
>     void _trealloc(void *ptr, size_t size);

Language Level: Extension
_trealloc changes the size of the tiled memory pointed to ptr to the specified size, in bytes. The contents of the tiled memory are unchanged up to the smaller of the new and old sizes. Any new tiled memory that is allocated is uninitialized.

To use _trealloc, you must compile with the /Gt compiler option. This option maps all realloc calls to _trealloc.

Note: The /Gt option maps all calls to regular memory management functions to their tiled versions. To prevent a call from being mapped, parenthesize the function name.

_trealloc works just like realloc except that it reallocates tiled memory instead of regular memory. Tiled memory will not to cross 64K boundaries, as long as the object is less than 64K in size. Objects larger than 64K in size are aligned on 64K boundaries, but will also cross 64K boundaries. If you have objects that may be accessed by 16-bit code, you should store them in tiled memory.

Tiled memory from the IBM C and C++ Compilers runtime heap is limited to 512 MB per process. You can also create your own heaps of tiled memory, which can be larger in size.

_trealloc can only reallocate memory allocated by the _tmalloc, _tcalloc, or _trealloc functions. If the memory was not allocated by one of these functions or was previously freed, a message appears and the program ends.

A debug version of this function, _debug_trealloc, is also available. Use the /Tm compiler option to map all _trealloc calls to _debug_trealloc.

Return Value
_trealloc returns a pointer to the reallocated tiled memory. If not enough storage is available or if size is 0, _trealloc returns NULL and the original block does not change.

Example
This example uses _trealloc to reallocate a block of tiled memory previously allocated by _tmalloc.

Note: You must compile this example with the /Gt option to enable tiled memory.

    #include <stdlib.h>
    #include <stdio.h>

    int main(void)
    {
       char *memoryPtr;

       if (NULL == (memoryPtr = (char*)malloc(100))) {
          puts("Could not allocate tiled memory.");
          exit(EXIT_FAILURE);
       }
       if (NULL == (memoryPtr = (char*)realloc(memoryPtr, 1000))) {
          puts("Unable to reallocate tiled memory.");
          exit(EXIT_FAILURE);
       }
       else
           puts("Successfully reallocated 1000 bytes of tiled memory.");
       free(memoryPtr);
       return 0;

       /****************************************************************
          The output should be similar to:

          Successfully reallocated 1000 bytes of tiled memory.
       ****************************************************************/
    }

Memory Management

_debug_calloc -- Allocate and Initialize Memory
_debug_trealloc -- Reallocate Tiled Memory Block
_msize -- Return Number of Bytes Allocated
realloc -- Change Reserved Storage Block Size
_tcalloc -- Reserve Tiled Storage Block
_tmalloc -- Reserve Tiled Storage Block
_tfree -- Free Tiled Storage Block
<malloc.h>
<stdlib.h>
/Gt compiler option
/Tm compiler option