Skip to content

Commit

Permalink
Update xrCore/xrMemory_align.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 12, 2018
1 parent f8e507b commit 0c41571
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
48 changes: 24 additions & 24 deletions src/xrCore/xrMemory_align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ typedef _W64 unsigned int uintptr_t;
* size_t alignment - alignment of memory
*
* Exit:
* Sucess: Pointer to memory block
* Faliure: Null
* Success: Pointer to memory block
* Failure: Null
*******************************************************************************/

void* __stdcall xr_aligned_malloc(size_t size, size_t alignment)
Expand All @@ -76,8 +76,8 @@ void* __stdcall xr_aligned_malloc(size_t size, size_t alignment)
* size_t offset - offset of memory from the alignment
*
* Exit:
* Sucess: Pointer to memory block
* Faliure: Null
* Success: Pointer to memory block
* Failure: Null
*
*******************************************************************************/

Expand All @@ -88,7 +88,7 @@ void* __stdcall xr_aligned_offset_malloc(size_t size, size_t align, size_t offse
if (!IS_2_POW_N(align))
{
errno = EINVAL;
return NULL;
return nullptr;
}
if (offset >= size && offset != 0)
size = offset + 1;
Expand All @@ -98,8 +98,8 @@ void* __stdcall xr_aligned_offset_malloc(size_t size, size_t align, size_t offse
/* gap = number of bytes needed to round up offset to align with PTR_SZ*/
gap = (0 - offset) & (PTR_SZ - 1);

if ((ptr = (uintptr_t)malloc(PTR_SZ + gap + align + size)) == (uintptr_t)NULL)
return NULL;
if ((ptr = (uintptr_t)malloc(PTR_SZ + gap + align + size)) == (uintptr_t)nullptr)
return nullptr;

retptr = ((ptr + PTR_SZ + gap + align + offset) & ~align) - offset;
((uintptr_t*)(retptr - gap))[-1] = ptr;
Expand Down Expand Up @@ -127,8 +127,8 @@ void* __stdcall xr_aligned_offset_malloc(size_t size, size_t align, size_t offse
* size_t alignment - alignment of memory
*
* Exit:
* Sucess: Pointer to re-allocated memory block
* Faliure: Null
* Success: Pointer to re-allocated memory block
* Failure: Null
*
*******************************************************************************/

Expand Down Expand Up @@ -158,8 +158,8 @@ void* __stdcall xr_aligned_realloc(void* memblock, size_t size, size_t alignment
* size_t offset - offset of memory from the alignment
*
* Exit:
* Sucess: Pointer to the re-allocated memory block
* Faliure: Null
* Success: Pointer to the re-allocated memory block
* Failure: Null
*
*******************************************************************************/

Expand All @@ -169,19 +169,19 @@ void* __stdcall xr_aligned_offset_realloc(void* memblock, size_t size, size_t al
uintptr_t movsz, reqsz;
int bFree = 0;

if (memblock == NULL)
if (memblock == nullptr)
{
return xr_aligned_offset_malloc(size, align, offset);
}
if (size == 0)
{
xr_aligned_free(memblock);
return NULL;
return nullptr;
}
if (offset >= size && offset != 0)
{
errno = EINVAL;
return NULL;
return nullptr;
}

stptr = (uintptr_t)memblock;
Expand All @@ -195,7 +195,7 @@ void* __stdcall xr_aligned_offset_realloc(void* memblock, size_t size, size_t al
if (!IS_2_POW_N(align))
{
errno = EINVAL;
return NULL;
return nullptr;
}

align = (align > PTR_SZ ? align : PTR_SZ) - 1;
Expand All @@ -220,16 +220,16 @@ void* __stdcall xr_aligned_offset_realloc(void* memblock, size_t size, size_t al
*/
if ((stptr + align + PTR_SZ + gap) < (uintptr_t)memblock)
{
if ((ptr = (uintptr_t)malloc(reqsz)) == (uintptr_t)NULL)
return NULL;
if ((ptr = (uintptr_t)malloc(reqsz)) == (uintptr_t)nullptr)
return nullptr;
bFree = 1;
}
else
{
if ((ptr = (uintptr_t)_expand((void*)stptr, reqsz)) == (uintptr_t)NULL)
if ((ptr = (uintptr_t)_expand((void*)stptr, reqsz)) == (uintptr_t)nullptr)
{
if ((ptr = (uintptr_t)malloc(reqsz)) == (uintptr_t)NULL)
return NULL;
if ((ptr = (uintptr_t)malloc(reqsz)) == (uintptr_t)nullptr)
return nullptr;
bFree = 1;
}
else
Expand Down Expand Up @@ -269,7 +269,7 @@ void __stdcall xr_aligned_free(void* memblock)
{
uintptr_t ptr;

if (memblock == NULL)
if (memblock == nullptr)
return;

ptr = (uintptr_t)memblock;
Expand All @@ -282,11 +282,11 @@ void __stdcall xr_aligned_free(void* memblock)
free((void*)ptr);
}

u32 __stdcall xr_aligned_msize(void* memblock)
size_t __stdcall xr_aligned_msize(void* memblock)
{
uintptr_t ptr;

if (memblock == NULL)
if (memblock == nullptr)
return 0;

ptr = (uintptr_t)memblock;
Expand All @@ -296,5 +296,5 @@ u32 __stdcall xr_aligned_msize(void* memblock)

/* ptr is the pointer to the start of memory block*/
ptr = *((uintptr_t*)ptr);
return (u32)_msize((void*)ptr);
return _msize((void*)ptr);
}
2 changes: 1 addition & 1 deletion src/xrCore/xrMemory_align.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define xrMemory_alignH
#pragma once

u32 __stdcall xr_aligned_msize(void*);
size_t __stdcall xr_aligned_msize(void*);
void __stdcall xr_aligned_free(void*);
void* __stdcall xr_aligned_malloc(size_t, size_t);
void* __stdcall xr_aligned_offset_malloc(size_t, size_t, size_t);
Expand Down

0 comments on commit 0c41571

Please sign in to comment.