Page 1 of 1

mallinfo question

Posted: Mon Sep 20, 2010 2:22 pm
by arasium
Hi everyone.

This code returns me a strange value.

Code: Select all

VPAD_Init();

struct mallinfo nfo = mallinfo();
struct mallinfo nfo2;
u32 length = 23801856;
				
				
cout << endl << endl << endl << "Memory used: " << nfo.uordblks << endl;
void* ptr = malloc(length);
nfo2 = mallinfo();
cout << "Allocated: " << nfo2.uordblks << endl;
cout << "Diff: " << nfo2.uordblks - nfo.uordblks << endl;
free(ptr);
nfo = mallinfo();
cout << "Memory used: " << nfo.uordblks << endl;
		
while(VPAD_ButtonsDown(0) == 0);

Can you explain me why the malloc reserved that amount of memory (and why it isn't freed at the end)?

Re: mallinfo question

Posted: Tue Sep 21, 2010 9:58 pm
by WinterMute
uordblocks is the size of memory handed out by malloc, including any free blocks still in the malloc tables. fordblocks will tell you the size of the memory in free chunks which will be later used to satisfy malloc requests.

See http://www.gnu.org/s/libc/manual/html_n ... alloc.html