Updated constructors of all SafeAllocatedMemory derivatives to use SizeT instead of int for the size parameter.

pull/83/head
David Hall 2019-07-27 12:48:33 -06:00
parent d7420b6770
commit 683280a945
5 changed files with 16 additions and 14 deletions

View File

@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
using Vanara.Extensions;
using Vanara.PInvoke;
namespace Vanara.InteropServices
{
@ -43,12 +44,12 @@ namespace Vanara.InteropServices
/// <param name="handle">The handle.</param>
/// <param name="size">The size of memory allocated to the handle, in bytes.</param>
/// <param name="ownsHandle">if set to <c>true</c> if this class is responsible for freeing the memory on disposal.</param>
public SafeCoTaskMemHandle(IntPtr handle, int size, bool ownsHandle = true) : base(handle, size, ownsHandle) { }
public SafeCoTaskMemHandle(IntPtr handle, SizeT size, bool ownsHandle = true) : base(handle, size, ownsHandle) { }
/// <summary>Initializes a new instance of the <see cref="SafeCoTaskMemHandle"/> class.</summary>
/// <param name="size">The size of memory to allocate, in bytes.</param>
/// <exception cref="System.ArgumentOutOfRangeException">size - The value of this argument must be non-negative</exception>
public SafeCoTaskMemHandle(int size) : base(size) { }
public SafeCoTaskMemHandle(SizeT size) : base(size) { }
/// <summary>Allocates from unmanaged memory to represent an array of pointers and marshals the unmanaged pointers (IntPtr) to the native array equivalent.</summary>
/// <param name="bytes">Array of unmanaged pointers</param>

View File

@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
using Vanara.Extensions;
using Vanara.PInvoke;
namespace Vanara.InteropServices
{
@ -42,12 +43,12 @@ namespace Vanara.InteropServices
/// <param name="handle">The handle.</param>
/// <param name="size">The size of memory allocated to the handle, in bytes.</param>
/// <param name="ownsHandle">if set to <c>true</c> if this class is responsible for freeing the memory on disposal.</param>
public SafeHGlobalHandle(IntPtr handle, int size, bool ownsHandle = true) : base(handle, size, ownsHandle) { }
public SafeHGlobalHandle(IntPtr handle, SizeT size, bool ownsHandle = true) : base(handle, size, ownsHandle) { }
/// <summary>Initializes a new instance of the <see cref="SafeHGlobalHandle"/> class.</summary>
/// <param name="size">The size of memory to allocate, in bytes.</param>
/// <exception cref="System.ArgumentOutOfRangeException">size - The value of this argument must be non-negative</exception>
public SafeHGlobalHandle(int size) : base(size) { }
public SafeHGlobalHandle(SizeT size) : base(size) { }
/// <summary>Allocates from unmanaged memory to represent an array of pointers and marshals the unmanaged pointers (IntPtr) to the native array equivalent.</summary>
/// <param name="bytes">Array of unmanaged pointers</param>

View File

@ -203,7 +203,7 @@ namespace Vanara.InteropServices
/// <summary>Initializes a new instance of the <see cref="SafeMemoryHandle{T}"/> class.</summary>
/// <param name="size">The size of memory to allocate, in bytes.</param>
/// <exception cref="System.ArgumentOutOfRangeException">size - The value of this argument must be non-negative</exception>
protected SafeMemoryHandle(int size = 0) : base(IntPtr.Zero, true)
protected SafeMemoryHandle(SizeT size = default) : base(IntPtr.Zero, true)
{
if (size < 0)
throw new ArgumentOutOfRangeException(nameof(size), "The value of this argument must be non-negative");
@ -217,7 +217,7 @@ namespace Vanara.InteropServices
/// <param name="handle">The handle.</param>
/// <param name="size">The size of memory allocated to the handle, in bytes.</param>
/// <param name="ownsHandle">if set to <c>true</c> if this class is responsible for freeing the memory on disposal.</param>
protected SafeMemoryHandle(IntPtr handle, int size, bool ownsHandle) : base(handle, ownsHandle) => sz = size;
protected SafeMemoryHandle(IntPtr handle, SizeT size, bool ownsHandle) : base(handle, ownsHandle) => sz = size;
/// <summary>Allocates from unmanaged memory to represent an array of pointers and marshals the unmanaged pointers (IntPtr) to the native array equivalent.</summary>
/// <param name="bytes">Array of unmanaged pointers</param>
@ -276,13 +276,13 @@ namespace Vanara.InteropServices
/// <summary>Initializes a new instance of the <see cref="SafeMemoryHandleExt{T}"/> class.</summary>
/// <param name="size">The size of memory to allocate, in bytes.</param>
/// <exception cref="System.ArgumentOutOfRangeException">size - The value of this argument must be non-negative</exception>
protected SafeMemoryHandleExt(int size) : base(size) { }
protected SafeMemoryHandleExt(SizeT size) : base(size) { }
/// <summary>Initializes a new instance of the <see cref="SafeMemoryHandleExt{T}"/> class.</summary>
/// <param name="handle">The handle.</param>
/// <param name="size">The size of memory allocated to the handle, in bytes.</param>
/// <param name="ownsHandle">if set to <c>true</c> if this class is responsible for freeing the memory on disposal.</param>
protected SafeMemoryHandleExt(IntPtr handle, int size, bool ownsHandle) : base(handle, size, ownsHandle) { }
protected SafeMemoryHandleExt(IntPtr handle, SizeT size, bool ownsHandle) : base(handle, size, ownsHandle) { }
/// <summary>Allocates from unmanaged memory to represent an array of pointers and marshals the unmanaged pointers (IntPtr) to the native array equivalent.</summary>
/// <param name="bytes">Array of unmanaged pointers</param>

View File

@ -1401,7 +1401,7 @@ namespace Vanara.PInvoke
/// <param name="ptr">The handle created by <see cref="HeapAlloc"/>.</param>
/// <param name="ownsHandle">if set to <c>true</c> this safe handle disposes the handle when done.</param>
/// <param name="size">The size, in bytes, of the allocated heap memory, if known.</param>
public SafeHeapBlock(IntPtr ptr, int size, bool ownsHandle = true) : base(ptr, size, ownsHandle)
public SafeHeapBlock(IntPtr ptr, SizeT size, bool ownsHandle = true) : base(ptr, size, ownsHandle)
{
}
@ -1410,7 +1410,7 @@ namespace Vanara.PInvoke
/// <param name="ptr">The handle created by <see cref="HeapAlloc"/>.</param>
/// <param name="ownsHandle">if set to <c>true</c> this safe handle disposes the handle when done.</param>
/// <param name="size">The size, in bytes, of the allocated heap memory, if known.</param>
public SafeHeapBlock(HHEAP hHeap, IntPtr ptr, int size, bool ownsHandle = true) : base(ptr, size, ownsHandle)
public SafeHeapBlock(HHEAP hHeap, IntPtr ptr, SizeT size, bool ownsHandle = true) : base(ptr, size, ownsHandle)
{
if (hHeap.IsNull) throw new ArgumentNullException(nameof(hHeap));
mm.HeapHandle = hHeap;
@ -1419,7 +1419,7 @@ namespace Vanara.PInvoke
/// <summary>Initializes a new instance of the <see cref="SafeMemoryHandle{T}"/> class.</summary>
/// <param name="size">The size of memory to allocate, in bytes.</param>
/// <exception cref="System.ArgumentOutOfRangeException">size - The value of this argument must be non-negative</exception>
public SafeHeapBlock(int size) : base(size)
public SafeHeapBlock(SizeT size) : base(size)
{
}
@ -1461,7 +1461,7 @@ namespace Vanara.PInvoke
/// </list>
/// </param>
/// <exception cref="System.ArgumentOutOfRangeException">size - The value of this argument must be non-negative</exception>
public SafeHeapBlock(HHEAP hHeap, int size = 0, HeapFlags flags = 0) : this(hHeap, IntPtr.Zero, 0)
public SafeHeapBlock(HHEAP hHeap, SizeT size = default, HeapFlags flags = 0) : this(hHeap, IntPtr.Zero, 0)
{
if (size < 0)
throw new ArgumentOutOfRangeException(nameof(size), "The value of this argument must be non-negative");

View File

@ -51,12 +51,12 @@ namespace Vanara.InteropServices
/// <param name="handle">The handle.</param>
/// <param name="size">The size of memory allocated to the handle, in bytes.</param>
/// <param name="ownsHandle">if set to <c>true</c> if this class is responsible for freeing the memory on disposal.</param>
public SafeLocalHandle(HLOCAL handle, int size, bool ownsHandle = true) : base((IntPtr)handle, size, ownsHandle) { }
public SafeLocalHandle(HLOCAL handle, SizeT size, bool ownsHandle = true) : base((IntPtr)handle, size, ownsHandle) { }
/// <summary>Initializes a new instance of the <see cref="SafeLocalHandle"/> class.</summary>
/// <param name="size">The size of memory to allocate, in bytes.</param>
/// <exception cref="System.ArgumentOutOfRangeException">size - The value of this argument must be non-negative</exception>
public SafeLocalHandle(int size) : base(size) { }
public SafeLocalHandle(SizeT size) : base(size) { }
/// <summary>
/// Allocates from unmanaged memory to represent an array of pointers and marshals the unmanaged pointers (IntPtr) to the native