/// <summary> /// Allocates the specified number of bytes from the heap. /// </summary> /// <param name="uFlags"> /// The memory allocation attributes. The default is the <see cref="LocalAllocFlags.LMEM_FIXED"/> value. This parameter can be one or more of the following values, except for the incompatible combinations that are specifically noted. /// </param> /// <param name="uBytes">The number of bytes to allocate. If this parameter is zero and the <paramref name="uFlags"/> parameter specifies <see cref="LocalAllocFlags.LMEM_MOVEABLE"/>, the function returns a handle to a memory object that is marked as discarded.</param> /// <returns> /// If the function succeeds, the return value is a handle to the newly allocated memory object. /// If the function fails, the return value is NULL. To get extended error information, call <see cref="GetLastError"/>. /// </returns> public static unsafe void *LocalAlloc(LocalAllocFlags uFlags, int uBytes) { // The length of SIZE_T and IntPtr vary with the bitness of the process. // For convenience to callers we want to expose the size of a memory allocation // as an Int32 no matter the process bitness. So safely 'upscale' the Int32 to // the appropriate IntPtr and call the native overload. return(LocalAlloc(uFlags, new IntPtr(uBytes))); }
public static extern unsafe void* LocalAlloc(LocalAllocFlags uFlags, IntPtr uBytes);
public static extern IntPtr LocalAlloc(LocalAllocFlags flags, uint size);
internal static extern IntPtr LocalAlloc(LocalAllocFlags uFlags, uint uBytes);
/// <summary> /// Allocates the specified number of bytes from the heap. /// </summary> /// <param name="uFlags"> /// The memory allocation attributes. The default is the <see cref="LocalAllocFlags.LMEM_FIXED"/> value. This parameter can be one or more of the following values, except for the incompatible combinations that are specifically noted. /// </param> /// <param name="uBytes">The number of bytes to allocate. If this parameter is zero and the <paramref name="uFlags"/> parameter specifies <see cref="LocalAllocFlags.LMEM_MOVEABLE"/>, the function returns a handle to a memory object that is marked as discarded.</param> /// <returns> /// If the function succeeds, the return value is a handle to the newly allocated memory object. /// If the function fails, the return value is NULL. To get extended error information, call <see cref="GetLastError"/>. /// </returns> public static unsafe void* LocalAlloc(LocalAllocFlags uFlags, int uBytes) { // The length of SIZE_T and IntPtr vary with the bitness of the process. // For convenience to callers we want to expose the size of a memory allocation // as an Int32 no matter the process bitness. So safely 'upscale' the Int32 to // the appropriate IntPtr and call the native overload. return LocalAlloc(uFlags, new IntPtr(uBytes)); }