Export (0) Print
Expand All
Expand Minimize
1 out of 1 rated this helpful - Rate this topic

GlobalReAlloc function

Changes the size or attributes of a specified global memory object. The size can increase or decrease.

Note  The global functions have greater overhead and provide fewer features than other memory management functions. New applications should use the heap functions unless documentation states that a global function should be used. For more information, see Global and Local Functions.

Syntax


HGLOBAL WINAPI GlobalReAlloc(
  _In_  HGLOBAL hMem,
  _In_  SIZE_T dwBytes,
  _In_  UINT uFlags
);

Parameters

hMem [in]

A handle to the global memory object to be reallocated. This handle is returned by either the GlobalAlloc or GlobalReAlloc function.

dwBytes [in]

The new size of the memory block, in bytes. If uFlags specifies GMEM_MODIFY, this parameter is ignored.

uFlags [in]

The reallocation options. If GMEM_MODIFY is specified, the function modifies the attributes of the memory object only (the dwBytes parameter is ignored.) Otherwise, the function reallocates the memory object.

You can optionally combine GMEM_MODIFY with the following value.

ValueMeaning
GMEM_MOVEABLE
0x0002

Allocates movable memory.

If the memory is a locked GMEM_MOVEABLE memory block or a GMEM_FIXED memory block and this flag is not specified, the memory can only be reallocated in place.

 

If this parameter does not specify GMEM_MODIFY, you can use the following value.

ValueMeaning
GMEM_ZEROINIT
0x0040

Causes the additional memory contents to be initialized to zero if the memory object is growing in size.

 

Return value

If the function succeeds, the return value is a handle to the reallocated memory object.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

If GlobalReAlloc reallocates a movable object, the return value is a handle to the memory object. To convert the handle to a pointer, use the GlobalLock function.

If GlobalReAlloc reallocates a fixed object, the value of the handle returned is the address of the first byte of the memory block. To access the memory, a process can simply cast the return value to a pointer.

If GlobalReAlloc fails, the original memory is not freed, and the original handle and pointer are still valid.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Global and Local Functions
GlobalAlloc
GlobalDiscard
GlobalLock
Memory Management Functions

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.