Shipwright/soh/src/buffers/heaps.c

41 lines
925 B
C
Raw Normal View History

#include "z64.h"
2022-04-02 07:47:22 -04:00
#include <assert.h>
#include <malloc.h>
2022-04-02 07:47:22 -04:00
#ifndef _MSC_VER
#include <unistd.h>
#endif
2022-04-02 07:47:22 -04:00
u8* gAudioHeap;
u8* gSystemHeap;
void Heaps_Alloc(void)
{
#ifdef _MSC_VER
2022-04-11 13:46:42 -04:00
gAudioHeap = (u8*)_aligned_malloc(AUDIO_HEAP_SIZE, 0x10);
gSystemHeap = (u8*)_aligned_malloc(SYSTEM_HEAP_SIZE, 0x10);
2022-04-02 07:47:22 -04:00
#elif defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L)
2022-04-11 13:46:42 -04:00
if (posix_memalign((void**)&gAudioHeap, 0x10, AUDIO_HEAP_SIZE) != 0)
2022-04-02 07:47:22 -04:00
gAudioHeap = NULL;
2022-04-11 13:46:42 -04:00
if (posix_memalign((void**)&gSystemHeap, 0x10, SYSTEM_HEAP_SIZE) != 0)
2022-04-02 07:47:22 -04:00
gSystemHeap = NULL;
#else
2022-04-11 13:46:42 -04:00
gAudioHeap = (u8*)memalign(0x10, AUDIO_HEAP_SIZE);
gSystemHeap = (u8*)memalign(0x10, SYSTEM_HEAP_SIZE);
2022-04-02 07:47:22 -04:00
#endif
assert(gAudioHeap != NULL);
assert(gSystemHeap != NULL);
}
void Heaps_Free(void)
{
#ifdef _MSC_VER
_aligned_free(gAudioHeap);
_aligned_free(gSystemHeap);
#else
free(gAudioHeap);
free(gSystemHeap);
#endif
}