Code: Select all
#define ALIGNED(nBytes) __attribute__((aligned(nBytes)))
// types:
typedef unsigned char byte_t;
// uint32_t, etc, are from <stdint.h> (this is c99 code)
struct dim2d
{
uint32_t y; /* Height */
uint32_t x; /* Width */
};
struct mipmap
{
struct dim2d xy; /* Mipmap dimensions */
byte_t ALIGNED (16) data[]; /* Pixel data */
};
...
pImage->p_mipmaps[i] = malloc (sizeof (struct mipmap) + size);
if ( pImage->p_mipmaps[i] == NULL )
{
// ignore this for now
// for ( uint32_t b = 0; b < i; b++ )
// free (pImage->p_mipmaps[b]);
pspDebugScreenPrintf ("Couldn't allocate %i bytes.\n"
, sizeof (struct mipmap) + size);
for ( uint32_t i = 1; i < 5; i++ )
{
byte_t *p_x = malloc (i * 1024 * 1024);
if ( p_x == NULL )
pspDebugScreenPrintf ("Couldn't allocate %i bytes.\n"
, i * 1024 * 1024);
else
{
pspDebugScreenPrintf ("COULD allocate %i bytes.\n"
, i * 1024 * 1024);
free (p_x);
}
}
return DDS_OUT_OF_MEMORY;
}
...
Code: Select all
Couldn't allocate 8208 bytes.
Couldn't allocate 1048576 bytes.
COULD allocate 2091752 bytes.
COULD allocate 3145728 bytes.
COULD allocate 4194304 bytes.
Code: Select all
...
struct mipmap
{
struct dim2d xy; /* Mipmap dimensions */
// Got rid of ALIGNED (16) from this:
byte_t data[]; /* Pixel data */
};
...
// Use memalign, align to 64 (16 still breaks):
pImage->p_mipmaps[i] = memalign (64, sizeof (struct mipmap) + size);