psPea wrote:I know that malloc allocates memory aligned on 16 bytes boundary, so maybe new does too.
That's not guaranteed! It depends on the implementation, and many allocate on 8 or 4 byte boundaries. Some are 16-byte boundary + 4 (allocate to a 16 byte boundary, then push a long, then return the result). That's why you use memalign instead of malloc/new - to GUARANTEE the boundary you need IS respected by the allocation.
>That's not guaranteed! It depends on the implementation
Well I was talking about the implimentation in the psp toolchain
I saw it on this forum but couldn't I find the thread.
maroxe wrote:thanks for you reply.
so i must understand that i always have to use memalign(16, whatever) instead of new/malloc?
Yes. If I remember correctly, the most you can count on for newlib is the largest natural type the CPU handles - for most CPUs, that's double, but on the PSP, it's just long/single.
maroxe wrote:thanks for you reply.
so i must understand that i always have to use memalign(16, whatever) instead of new/malloc?
Yes. If I remember correctly, the most you can count on for newlib is the largest natural type the CPU handles - for most CPUs, that's double, but on the PSP, it's just long/single.
Someone correct me if I'm wrong on that. :)
You can specify the default alignment for malloc() when building newlib with the MALLOC_ALIGNMENT define. This is currently set to 16 bytes - it's that high for precisely the reason this thread was started - people don't often know which data structures need to be aligned for hardware.
I wanted to point out though, that when dealing with an array of structs allocated via new, you have to be extremely careful about passing them off to hardware. The compiler will insert a bit of housekeeping data at the beginning of your allocation, so that it can properly destroy things when you call delete[]. IOW, you can't count on 128-bit alignment when using array new.
Anyway, if sceGuDrawArray() requires 32-bit alignment then it shouldn't matter because whatever housekeeping that array new tacks on will likely be at least 32-bit aligned.
i steal don't understand, if a data is 32bits aligned, it will be 16bits aligned. So why in every tutorial for PSP we use memalign(16, ...)?
Also, the list passed to sceGu, f don't specify "__attribute__((aligned(16)))" no vertexis shown at the screen