mirror of
https://github.com/Yours3lf/rpi-vk-driver.git
synced 2024-12-01 13:24:20 +01:00
32 lines
404 B
C
32 lines
404 B
C
|
#pragma once
|
||
|
|
||
|
|
||
|
void* alignedAlloc( unsigned bytes, unsigned alignment = 16 )
|
||
|
{
|
||
|
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 );
|
||
|
}
|