Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How does free() know how many bytes to free?

Answers were Sorted based on User's Feedback



How does free() know how many bytes to free?..

Answer / sekhar

free takes the pointer variable as argument. The intial
data at that location holds a value of number of bytes that
pointer is pointing to. Based on that information, it frees
the memory.

Is This Answer Correct ?    9 Yes 5 No

How does free() know how many bytes to free?..

Answer / vadivel t

Heap memory menager is a person, who is responsible for
dynamic memory allocation. He will maintains a internal
data structure(table) to update the information on free and
allocated memory pools. when memory is allocated using
malloc or calloc, the heap memory manager will update the
table(which tells, no of bytes allocated to a particular
pointer) and returns the base address to the application.
when application calls free() with the pointer to be freed
as a argument, free will look into the table which holds no
of bytes allocated for that pointer. And it will free those
many bytes from the base address. Again the freed memory
shall be added to a free memory pool so that other fellows
who needs memory can utilise it.

Is This Answer Correct ?    6 Yes 2 No

How does free() know how many bytes to free?..

Answer / guest

The malloc/free implementation remembers the size of each
block allocated and returned.

Is This Answer Correct ?    6 Yes 4 No

How does free() know how many bytes to free?..

Answer / vrushali

Whenever we call malloc() for allocating memory. The value
of the starting address is stored in a virtual memory tables.
So whenever free() is called then using the starting memory
location free () will have an entry of the bytes allocated
and to be freed. It can do it using this entry then entry is
deleted also.
This is pure OS concept.

Please reply here if you are not able to understand my answer.

Is This Answer Correct ?    4 Yes 3 No

How does free() know how many bytes to free?..

Answer / sourisengupta

free(ptr);

free takes the pointer variable as argument. The intial
data at that location holds a value of number of bytes that
pointer is pointing to. According to the information, it
frees
the memory.

Is This Answer Correct ?    4 Yes 4 No

How does free() know how many bytes to free?..

Answer / rpjanaka

Then, is there a way to get out the number of bytes that
heap manager going to free, when I call free() function.

Is This Answer Correct ?    1 Yes 1 No

How does free() know how many bytes to free?..

Answer / pearl

This is possible if your OS providing the system calls to access those memory manager data structure.

Is This Answer Correct ?    0 Yes 0 No

How does free() know how many bytes to free?..

Answer / suchita

frees a block allocated with malloc()

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More C Interview Questions

Is there something we can do in C but not in C++? Declare variable names that are keywords in C++ but not C.

2 Answers   Infosys,


What is the real difference between arrays and pointers?

27 Answers   Hexaware, Logic Pro, TCS,


What is the data segment that is followed by c?

0 Answers  


Explain how can I convert a number to a string?

0 Answers  


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

2 Answers   Aricent, Manipal University,


Explain null pointer.

0 Answers  


what is pointer

1 Answers   TCS,


Is r written in c?

0 Answers  


what is an array

5 Answers  


Efficient data structure for store/search list of 1000 records a)array b)double linked list c)circular queue d)hash table

3 Answers   Value Labs,


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

0 Answers   HCL,


How can you tell whether two strings are the same?

0 Answers  


Categories