19 #ifndef INC_KY_Kernel_HeapMH_SysAllocMalloc_H
20 #define INC_KY_Kernel_HeapMH_SysAllocMalloc_H
24 #if defined(KY_OS_WIN32) || defined(KY_OS_WINCE) || defined(KY_OS_XBOX) || defined(KY_OS_XBOX360)
26 #elif defined(KY_OS_WII)
38 #if defined(KY_OS_WII)
42 UByte *m2arenaLo = (UByte*) OSGetMEM2ArenaLo();
43 UByte *m2arenaHi = (UByte*) OSGetMEM2ArenaHi();
44 if (size > 0 && (m2arenaLo + size < m2arenaHi))
45 m2arenaHi = m2arenaLo + size;
46 OSSetMEM2ArenaLo(m2arenaHi);
49 ::new(PrivateData) SysAllocStatic(m2arenaLo, (UByte*)m2arenaHi-(UByte*)m2arenaLo);
56 #if (defined(KY_OS_WIN32) || defined(KY_OS_WINCE) || defined(KY_OS_XBOX) || defined(KY_OS_XBOX360)) && !defined(KY_CC_GNU)
57 virtual void*
Alloc(UPInt size, UPInt align)
59 return _aligned_malloc(size, align);
62 virtual void Free(
void* ptr, UPInt size, UPInt align)
64 KY_UNUSED2(size, align);
68 virtual void*
Realloc(
void* oldPtr, UPInt oldSize, UPInt newSize, UPInt align)
71 return _aligned_realloc(oldPtr, newSize, align);
73 #elif defined(KY_OS_PS3)
74 virtual void*
Alloc(UPInt size, UPInt align)
76 return memalign(align, size);
79 virtual void Free(
void* ptr, UPInt size, UPInt align)
81 KY_UNUSED2(size, align);
85 virtual void*
Realloc(
void* oldPtr, UPInt oldSize, UPInt newSize, UPInt align)
88 return reallocalign(oldPtr, newSize, align);
91 #elif defined(KY_OS_WII)
92 virtual void*
Alloc(UPInt size, UPInt align)
94 return GetAllocator()->Alloc(size, align);
97 virtual void Free(
void* ptr, UPInt size, UPInt align)
99 GetAllocator()->Free(ptr, size, align);
102 virtual void*
Realloc(
void* oldPtr, UPInt oldSize, UPInt newSize, UPInt align)
105 if (GetAllocator()->ReallocInPlace(oldPtr, oldSize, newSize, align))
108 newPtr = GetAllocator()->Alloc(newSize, align);
111 memcpy(newPtr, oldPtr, (newSize < oldSize) ? newSize : oldSize);
112 GetAllocator()->Free(oldPtr, oldSize, align);
119 UPInt PrivateData[(
sizeof(SysAllocStatic) +
sizeof(UPInt)) /
sizeof(UPInt)];
120 SysAllocStatic* GetAllocator() {
return (SysAllocStatic*) PrivateData; }
123 virtual void*
Alloc(UPInt size, UPInt align)
125 if (align <
sizeof(
void*))
126 align =
sizeof(
void*);
128 UPInt ptr = (UPInt)malloc(size+(align-1)+
sizeof(UPInt));
132 aligned = (UPInt(ptr) +
sizeof(UPInt) + (align-1)) & ~(align-1);
135 *(((UPInt*)aligned)-1) = aligned-ptr;
137 return (
void*)aligned;
140 virtual void Free(
void* ptr, UPInt size, UPInt align)
144 UPInt src = UPInt(ptr) - *(((UPInt*)ptr)-1);
149 virtual void*
Realloc(
void* oldPtr, UPInt oldSize, UPInt newSize, UPInt align)
151 void* newPtr =
Alloc(newSize, align);
154 memcpy(newPtr, oldPtr, (newSize < oldSize) ? newSize : oldSize);
155 Free(oldPtr, oldSize, align);
virtual void Free(void *ptr, UPInt size, UPInt align)
Frees the specified memory buffer.
Definition: HeapMH_SysAllocMalloc.h:63
virtual void * Alloc(UPInt size, UPInt align)
Allocates a buffer of the specified size, with the specified alignment.
Definition: HeapMH_SysAllocMalloc.h:58
This implementation of SysAlloc is used by default by the BaseSystem to allocate and free memory...
Definition: HeapMH_SysAllocMalloc.h:35
Adds to the SysAlloc class support for restricting instantiation to a single object.
Definition: SF_SysAlloc.h:267
Definition: gamekitcrowddispersion.h:20
virtual void * Realloc(void *oldPtr, UPInt oldSize, UPInt newSize, UPInt align)
Re-allocates a buffer to a new size.
Definition: HeapMH_SysAllocMalloc.h:69