Where Do malloc() / free() Store Allocated Sizes and Addresses?

Most commonly, glibc will try to reduce inefficiencies in the heap by preallocating chunks and reusing free()d chunks. The aim of malloc and free is to do this quickly and avoid too much fragmentation. This depends on the hardware too; different architectures have different caching mechanisms.

Virtual memory mapping per-process is also a concern here. Looking through the malloc source, what you will find is that no one system keeps a table of addresses, although free()d space is kept for a while incase it's needed again shortly.

There are lots of ways in which malloc/free can store the size of the memory area. For example, it might be stored just before the area returned by malloc. Or it might be stored in a lookup table elsewhere.

Or it might be stored implicitly: some areas might be reserved for specific sizes of allocations.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions