[uClibc] Help Required(ucLibc0.9.2x)-(Explaination)

sandeep malik malik_mca1 at rediffmail.com
Tue Feb 22 04:26:34 UTC 2005


  
Hi....

What is bugging me is, the second for loop and not the first one, where i am doing 9 allocations out of which 3 i am freeing with in the same loop and rest 6 i am freeing in next for loop....

Point A:
	
for (i=8; i <= 10 ; i++)
{
       	t[i] = (int *) OS_ADPT_Allocate_Memory(NULL,3553);
	t[i+3] = (int *)  OS_ADPT_Allocate_Memory(NULL,53);
       t[i+6] = (int *) OS_ADPT_Allocate_Memory(NULL,553);
//Doing 9 allocations of which three below are getting freed below
	OS_ADPT_Deallocate_Memory(t[i]);
}
for(i=1; i<=6 ; i++)
{
//Rest 6 allocation are freed here
	OS_ADPT_Deallocate_Memory(t[i+10]);
	sleep(1);
	printf("\nIn the for Loop allocating memory\n");
}  
Point B:


What i am saying is memory should be same when it is listed at Point A and then again at Point B. But here i am loosing 8K of memory.... Could you please explain me the reason for same......

Thanks and Regards,
Sandeep Malik


On Mon, 21 Feb 2005 sandeep  malik wrote :
>Hi....
>I am runring the following sample code using uClibc. But everytime the code completes one execution 8K(2 pages) of memory are gone...i am running this code on a board w/o MMU...so i am using malloc instead of malloc-simple or malloc-standard....i tried code with uClibc 0.9.20, uClibc 0.9.25 and even uClibc-0.9.27 but still results were same....can any one please help me to get out of this and help me understand what's happening here.......
>
>Thanking you in advance....
>regds,
>Malik.
>___________________________________________________________________
>#include <stdio.h>
>#include "types.h"
>#include "SM.h"
>#include "Web.h"
>#include "debugmodule.h"
>#include "compiletimeoptions.h"
>#include<sys/types.h>
>#include<sys/stat.h>
>#include<sys/ioctl.h>
>#include<fcntl.h>
>#include<stdio.h>
>
>#define	MEMORY_SHOWING				1
>
>#if MEMORY_SHOWING
>
>#define SHOW_MEM                                1
>
>int procMemFD;
>void Show_MemoryInit();
>void List_Memory();
>#endif
>
>void TempProcess();
>void main()
>{
>int	*t[20];
> 	pthread_t			tThread;
>     int           retVal;
>
>#if MEMORY_SHOWING
> 	Show_MemoryInit();
>     List_Memory();
>#endif
> 	while (1){
> 		//printf("Main: \n");
> 	//	usleep(5000000);
> 		sleep(40);
> 		printf("Woke from Sleep \n");
> 		printf("\ngoing to call TempProcess\n");
> 		#if MEMORY_SHOWING
> 		//List_Memory();
> 		TempProcess();
> 		#endif
> 	}
>
>}
>void TempProcess()
>{
> 	int	*t[20];
> 	int i;
>
> 	for (i=0; i <= 7 ; i++)
> 	{// Using a wrapper for malloc
>         	t[i] = (int *) OS_ADPT_Allocate_Memory(NULL,3553);
>
> 		sleep(1);
> 		List_Memory();
> 	}
> 	List_Memory();
> 	printf("\n Now going to free Just check putting back or not.....\n");
> 	for (i=8; i <= 10 ; i++)
> 	{
>         	t[i] = (int *) OS_ADPT_Allocate_Memory(NULL,3553);
> 		t[i+3] = (int *)  OS_ADPT_Allocate_Memory(NULL,53);
> 	       t[i+6] = (int *) OS_ADPT_Allocate_Memory(NULL,553);
> 		OS_ADPT_Deallocate_Memory(t[i]);	//wrapper for free
> 	}
> 	for(i=1; i<=6 ; i++)
> 	{
> 		OS_ADPT_Deallocate_Memory(t[i+10]);
> 		sleep(1);
> 		printf("\nIn the for Loop allocating memory\n");
> 	}
> 	sleep(5);
>//	List_Memory();
>
> 	printf("\n This should be what is shown above.....\n");
> 	sleep(5);
> 	List_Memory();
>
>}
>#if MEMORY_SHOWING
>void Show_MemoryInit()
>{
>         procMemFD = open("/dev/ProcMemInfo", O_RDWR, 0);
>         if(procMemFD < 0) {
>                 printf("Sorry cant open Proc Mem DRIVER!!!\n");
>         } else {
>                 printf("Proc Mem opened with %d\n", procMemFD);
>         }
>}
>void List_Memory()
>{
>         if(ioctl(procMemFD, SHOW_MEM) >= 0) {
>         } else {
>                 printf("Memory : ioctl failed\n");
>         }
>}
>#endif
>
>
>Thanks and Regards,
>Sandeep Malik
>_______________________________________________
>uClibc mailing list
>uClibc at uclibc.org
>http://uclibc.org/mailman/listinfo/uclibc


Thanks and Regards,
Sandeep Malik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20050222/33335cce/attachment.htm 


More information about the uClibc mailing list