[Cbe-oss-dev] Memalign and free doesn't work
Jonathan Adamczewski
jadamcze at utas.edu.au
Wed Oct 14 10:16:46 EST 2009
Philip Pratt-Szeliga wrote:
> Hello,
>
> I am noticing that memalign and free doesn't work on the ps3.
>
> code:
> =======================
> #include <malloc.h>
>
> static void printMemUsage()
> {
> struct mallinfo mi;
> mi = mallinfo();
> printf("MemUsage: %d\n", mi.arena);
> }
>
> int main(unsigned long long spe_id, unsigned long long
> program_data_ea, unsigned long long env)
> {
> printMemUsage();
> void * triangles_local_mem = memalign(16, 65535);
> free(triangles_local_mem);
> printMemUsage();
> return 0;
> }
> =======================
>
> compile:
> spu-gcc cell_function.c
>
> results:
> #./a.out
> MemUsage: 0
> MemUsage: 68848
> #
>
> Am I doing something wrong?
To go back to the original problem, I tried a couple of things -
there is no problem with memalign and free - at least for me.
I get the same kind of numbers - I think your mistake is probably in
your interpretation of the meaning of mi.arena.
Consider :
=======================
int main(unsigned long long spe_id, unsigned long long
program_data_ea, unsigned long long env)
{
printMemUsage();
void *t1, *t2, *t3;
t1 = memalign(16, 65535);
printMemUsage();
t2 = memalign(16, 65535);
printMemUsage();
t3 = memalign(16, 65535);
printMemUsage();
free(t3);
printMemUsage();
free(t2);
printMemUsage();
free(t1);
printMemUsage();
t1 = memalign(16, 65535);
printMemUsage();
return 0;
}
=======================
And the output:
MemUsage: 0
MemUsage: 68768
MemUsage: 138400
MemUsage: 208032
MemUsage: 208032
MemUsage: 68768
MemUsage: 68768
MemUsage: 68768
You can see that mi.arena is not updated on every call to free(),
but that memalign() and free() appear to be doing the right thing.
(I'm using Debian's newlib-spu-1.17.0-3. spu-newlib-1.16.0-17 from
BSC has a patch for a different malloc/free/memalign implementation,
which may yield different results)
j.
More information about the cbe-oss-dev
mailing list