Memory Allocation

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Memory Allocation.

Use these routines to allocate, free, and reallocate memory.

Memory-Allocation Routines

RoutineUse.NET Framework equivalent
_alloca, _mallocaAllocate memory from stackNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
callocAllocate storage for array, initializing every byte in allocated block to 0Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_calloc_dbgDebug version of calloc; only available in the debug versions of the run-time librariesNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
operator deleteFree allocated blockNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
operator delete[]Free allocated blockNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_expandExpand or shrink block of memory without moving itNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_expand_dbgDebug version of _expand; only available in the debug versions of the run-time librariesNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
freeFree allocated blockNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_free_dbgDebug version of free; only available in the debug versions of the run-time librariesNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_freeaFree allocated block from stackNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_get_heap_handleGet Win32 HANDLE of the CRT heap.Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_heapaddAdd memory to heapNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_heapchkCheck heap for consistencyNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_heapminRelease unused memory in heapNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_heapsetFill free heap entries with specified valueNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_heapwalkReturn information about each entry in heapNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
mallocAllocate block of memory from heapNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_malloc_dbgDebug version of malloc; only available in the debug versions of the run-time librariesNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_msizeReturn size of allocated blockNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_msize_dbgDebug version of _msize; only available in the debug versions of the run-time librariesNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
newAllocate block of memory from heapNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
new[]Allocate block of memory from heapNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_query_new_handlerReturn address of current new handler routine as set by _set_new_handlerNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_query_new_modeReturn integer indicating new handler mode set by _set_new_mode for mallocNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
reallocReallocate block to new sizeNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_realloc_dbgDebug version of realloc; only available in the debug versions of the run-time librariesNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_set_new_handlerEnable error-handling mechanism when new operator fails (to allocate memory) and enable compilation of Standard Template Libraries (STL)Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.
_set_new_modeSet new handler mode for mallocNot applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Run-Time Routines by Category

Show: