size_t VMemoryManager_CRT::AlignedMemSize(void* ptr, int iAlignment)
{
  // Not all memory size functions cope with NULL pointer
  if(ptr == NULL)
    return 0;

#if defined(WIN32)  || defined (_VISION_XENON) 
#if defined(VBASE_USE_CRT_DEBUG)
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
  return _aligned_msize_dbg(ptr, iAlignment, 0);
#else
  return _msize_dbg(ptr, _NORMAL_BLOCK);//@@@@ VStudio < 2005 and code might be wrong
#endif
#else
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
  return _aligned_msize(ptr, iAlignment, 0);
#else
  return _msize(ptr);//@@@@ VStudio < 2005 and code might be wrong
#endif
#endif


#elif defined (_VISION_PS3)
  return malloc_usable_size(ptr);



#elif defined (_VISION_POSIX)
  return 0; // TODO: IOS

#elif defined (_VISION_PSP2)
  return malloc_usable_size(ptr);

#elif defined (_VISION_WIIU)
  return 0; // XXCK

#else
#error Undefined platform!
#endif
}
Ejemplo n.º 2
0
extern "C" void* __cdecl _aligned_offset_recalloc_base(
    void*  block,
    size_t count,
    size_t size,
    size_t align,
    size_t offset
    )
{
    size_t user_size  = 0;    /* wanted size, passed to aligned realoc */
    size_t start_fill = 0;    /* location where aligned recalloc starts to fill with 0 */
                              /* filling must start from the end of the previous user block */
    void * retptr     = nullptr; /* result of aligned recalloc*/

    /* ensure that (size * num) does not overflow */
    if (count > 0)
    {
        _VALIDATE_RETURN_NOEXC((_HEAP_MAXREQ / count) >= size, ENOMEM, nullptr);
    }

    user_size = size * count;

    if (block != nullptr)
    {
        start_fill = _aligned_msize(block, align, offset);
    }

    retptr = _aligned_offset_realloc_base(block, user_size, align, offset);

    if (retptr != nullptr)
    {
        if (start_fill < user_size)
        {
            memset ((char*)retptr + start_fill, 0, user_size - start_fill);
        }
    }
    return retptr;
}