
nick at ccl4
Nov 29, 2006, 7:16 AM
Post #5 of 7
(294 views)
Permalink
|
|
Re: [PATCH] Re: [PATCH] abstract mempool header testing
[In reply to]
|
|
On Wed, Nov 29, 2006 at 09:01:18AM -0500, Jarkko Hietaniemi wrote: > Dave Mitchell wrote: > > On Mon, Nov 27, 2006 at 12:25:53PM -0500, Jarkko Hietaniemi wrote: > >> The attached patch replaces the earlier one and it adds not doing > >> the PERL_TRACK_MEMPOOL if the PerlMemShared* are just plain malloc > >> et alia. > > > > But I thought the whole point of PERL_TRACK_MEMPOOL was to simulate the > > behaviour of fussy systems like win32, so that people who do their > > development on UNIX don't write code that breaks on windows? > > So thought I. But I cannot see how that can work at the moment. > But I am hopefully wrong, and hopefully Jan will pipe up soon. > (My intelligence sources say that might happen soon.) Well, I'm not Jan, but as I understand it, if you have PERL_TRACK_MEMPOOL defined then this structure: struct perl_memory_debug_header { tTHX interpreter; # ifdef PERL_POISON MEM_SIZE size; # endif struct perl_memory_debug_header *prev; struct perl_memory_debug_header *next; }; is stored before every memory allocation with New/Renew etc (by increasing the allocation request from the real system malloc, writing that structure at the head, then returning a pointer to the byte after the structure). The prev and next pointers are used for a doubly-linked-list to hang all the allocations from that ithread together. At Safefree() time a check is made that you're in the same interpreter. (Else you panic) At ithread closedown the interpreter chases round the linked list and (system) free()s any remaining memory. So if you're using something like valgrind it will spot if you're still reading it too late. With PERL_POISON also defined memory is scribbled on before it is freed. I think that's all. Nicholas Clark
|