Date: Thu, 25 Feb 2010 17:00:46 +0000 From: RW <rwmaillists@googlemail.com> To: freebsd-hackers@freebsd.org Subject: Re: 2 bytes allocated problems Message-ID: <20100225170046.541e4b8c@gumby.homeunix.com> In-Reply-To: <86sk8qpfx8.fsf@ds4.des.no> References: <983a1cf21002240544s59006035ifbf0ef7eb045e44f@mail.gmail.com> <86eikar7gv.fsf@ds4.des.no> <4B858007.1000008@gmail.com> <86sk8qpfx8.fsf@ds4.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 24 Feb 2010 20:55:15 +0100 Dag-Erling Sm=F8rgrav <des@des.no> wrote: > Andrey Zonov <andrey.zonov@gmail.com> writes: > > Dag-Erling Sm=F8rgrav <des@des.no> writes: > > > Pointers have no boundareis in C. > > And how free() finds that the need to release? >=20 > That is a very simple question with a very complicated answer. A simple answer is that information about the amount of memory allocated is stored at the time it's allocated. And free() can find that data from the pointer. I don't know how it works in FreeBSD, but a traditional method is to put the metadata just before the block of memory returned by malloc - so free() can find it with a simple fixed offset. Note that the allocation algorithm is free to allocate more memory than it needs to, it doesn't need to record what malloc actually asked for, and it doesn't need to know about data structures that are put in that memory.=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100225170046.541e4b8c>