Malloc implementation isnt simple as above. It involves system call sbrk() to request memory to operating system and a suitable data structure to allocate and deallocate memory from available memory blocks. Proper implementation of malloc is given in Kerningha ritchie text book :) *Muthuraj R IV th Year , ISE PESIT , Bangalore*
On Tue, Aug 2, 2011 at 11:03 PM, ghsjgl k <[email protected]> wrote: > #include<stdio.h> > int size 1000 > void *a; > static int freeindex; > void *malloc(int n) > {t > if( n<(1000-freeindex) ) > { > p=freeindex; > freeindex=freeindex+n; > } > else > printf(" insufficient memory"); > return a+p; > } > > i dont think it exactly correct but you have to use the concept of the > static variable here because it will remember the value of variable during > recalling of function > > i presented here it because by seeing atleast one of you will get the > idea..... > so friends try to understand it write even i want the correct code for it > > i think my code wont work > > > > On Tue, Aug 2, 2011 at 10:10 PM, rShetty <[email protected]> wrote: > >> Could anyone provide an algorithm/code and explanation for >> implementation of malloc() in C . >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
