RAD Studio |  |

alloc.h
Collapse All

The following functions, macros, and classes are provided in alloc.h:

Topics

Name | Description
_heapchk | Header File malloc.h Category Memory Routines Syntax int _heapchk(void); Description Checks and verifies the heap. _heapchk walks through the heap and examines each block, checking its pointers, size, and other critical attributes. Return Value One of the following values:
_heapmin | Header File malloc.h Category Memory Routines Prototype int _heapmin(void); Description Release unused heap areas. The _heapmin function returns unused areas of the heap to the operating system. This allows other processes to use blocks that have been allocated and then freed. Due to fragmentation of the heap, _heapmin might not always be able to return unused memory to the operating system; this is not an error. Return Value _heapmin returns 0 if it is successful, or -1 if an error occurs. Portability
_heapset | Header File malloc.h Category Memory Routines Prototype int _heapset(unsigned int fillvalue); Description Fills the free blocks on the heap with a constant value. _heapset checks the heap for consistency using the same methods as _heapchk. It then fills each free block in the heap with the value contained in the least significant byte of fillvalue. This function can be used to find heap-related problems. It does not guarantee that subsequently allocated blocks will be filled with the specified value. Return Value One of the following values:
_msize | Header File malloc.h Category Memory Routines Prototype size_t _msize(void *block); Description Returns the size of a heap block. _msize returns the size of the allocated heap block whose address is block. The block must have been allocated with malloc, calloc, or realloc. The returned size can be larger than the number of bytes originally requested when the block was allocated. Return Value _msize returns the size of the block in bytes. Example
_rtl_heapwalk | Header File malloc.h Category Memory Routines Prototype int _rtl_heapwalk(_HEAPINFO *hi); Description Inspects the heap node by node. Note: This function replaces _heapwalk which is obsolete. _rtl_heapwalk assumes the heap is correct. Use _heapchk to verify the heap before using _rtl_heapwalk. _HEAPOK is returned with the last block on the heap. _HEAPEND will be returned on the next call to _rtl_heapwalk. _rtl_heapwalk receives a pointer to a structure of type _HEAPINFO (declared in malloc.h). Note that the _HEAPINFO structure must be allocated on the heap (using malloc()). You can’t pass the address of a variable declared on the stack. For the... more
calloc | Header File alloc.h, stdlib.h Category Memory Routines Prototype void *calloc(size_t nitems, size_t size); Description Allocates main memory. calloc provides access to the C memory heap. The heap is available for dynamic allocation of variable-sized blocks of memory. Many data structures, such as trees and lists, naturally employ heap memory allocation. calloc allocates a block of size nitems * size. The block is initialized to 0. Return Value calloc returns a pointer to the newly allocated block. If not enough space exists for the new block or if nitems or size is 0, calloc returns NULL. Example
free | Header File alloc.h, stdlib.h Category Memory Routines Prototype void free(void *block); Description Frees allocated block. free deallocates a memory block allocated by a previous call to calloc, malloc, or realloc. Return Value None. Example
heapcheck | Header File alloc.h Category Memory Routines Prototype int heapcheck(void); Description Checks and verifies the heap. heapcheck walks through the heap and examines each block, checking its pointers, size, and other critical attributes. Return Value The return value is less than 0 for an error and greater than 0 for success. The return values and their meaning are as follows:
heapcheckfree | Header File alloc.h Category Memory Routines Prototype int heapcheckfree(unsigned int fillvalue); Description Checks the free blocks on the heap for a constant value. Return Value The return value is less then 0 for an error and greater than 0 for success. The return values and their meaning are as follows:
heapchecknode | Header File alloc.h Category Memory Routines Prototype int heapchecknode(void *node); Description Checks and verifies a single node on the heap. If a node has been freed and heapchecknode is called with a pointer to the freed block, heapchecknode can return _BADNODE rather than the expected _FREEENTRY. This is because adjacent free blocks on the heap are merged, and the block in question no longer exists. Return Value One of the following values:
heapfillfree | Header File alloc.h Category Memory Routines Prototype int heapfillfree(unsigned int fillvalue); Description Fills the free blocks on the heap with a constant value. Return Value One of the following values:
heapwalk | Header File alloc.h Category Memory Routines Prototype int heapwalk(struct heapinfo *hi); Description heapwalk is used to “walk” through the heap, node by node. heapwalk assumes the heap is correct. Use heapcheck to verify the heap before using heapwalk. _HEAPOK is returned with the last block on the heap. _HEAPEND will be returned on the next call to heapwalk. heapwalk receives a pointer to a structure of type heapinfo (declared in alloc.h). For the first call to heapwalk, set the hi.ptr field to null. heapwalk returns with hi.ptr containing the address of the first block. hi.size holds the size of the... more
malloc | Header File alloc.h, stdlib.h Category Memory Routines Prototype void *malloc(size_t size); Description malloc allocates a block of size bytes from the memory heap. It allows a program to allocate memory explicitly as it’s needed, and in the exact amounts needed. Allocates main memory.The heap is used for dynamic allocation of variable-sized blocks of memory. Many data structures, for example, trees and lists, naturally employ heap memory allocation. In the large data models, all the space beyond the program stack to the end of available memory is available for the heap. Return Value On success, malloc returns a pointer to the... more
realloc | Header File alloc.h, stdlib.h Category Memory Routines Prototype void *realloc(void *block, size_t size); Description Reallocates main memory. realloc attempts to shrink or expand the previously allocated block to size bytes. If size is zero, the memory block is freed and NULL is returned. The block argument points to a memory block previously obtained by calling malloc, calloc, or realloc. If block is a NULL pointer, realloc works just like malloc. realloc adjusts the size of the allocated block to size, copying the contents to a new location if necessary. Return Value realloc returns the address of the reallocated block, which... more
stackavail | Header File malloc.h Category Memory Routines Prototype size_t stackavail(void); Description Gets the amount of available stack memory. stackavail returns the number of bytes available on the stack. This is the amount of dynamic memory that alloca can access. Return Value stackavail returns a size_t value indicating the number of bytes available. Example

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!