1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2024-12-02 14:24:14 +01:00
rpi-vk-driver/driver/AlignedAllocator.c

34 lines
439 B
C
Raw Normal View History

2018-10-15 23:37:09 +02:00
#define _POSIX_C_SOURCE 200809L
2018-08-26 15:11:43 +02:00
#include "AlignedAllocator.h"
void* alignedAlloc( unsigned bytes, unsigned alignment )
{
if( !bytes )
{
return 0;
}
const unsigned maxBytes = 1024 * 1024 * 1024; //1GB is max on RPi
if( bytes > maxBytes )
{
return 0; //bad alloc
}
void* pv = 0;
if( posix_memalign( &pv, alignment, bytes ) )
{
pv = 0; //allocation failed
}
return pv;
}
void alignedFree( void* p )
{
free( p );
}