Eliminate class allocators and deallocators?

Denis Koroskin 2korden at gmail.com
Wed Oct 7 17:49:15 PDT 2009


On Thu, 08 Oct 2009 04:39:20 +0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Denis Koroskin wrote:
>> On Thu, 08 Oct 2009 04:13:12 +0400, Andrei Alexandrescu  
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> Denis Koroskin wrote:
>>>> I'm not sure you will convince people to use foo.recycle() instead of  
>>>> foo.delete(). Not only it's slower, I believe recycling an object  
>>>> works for hiding bugs: accessing a recycled object - obviously a bug  
>>>> - will no longer be detected.
>>>
>>> Is anyone under the illusion that today there's any detection going on?
>>>
>>> Andrei
>>  There is none, but it's possible. It's just not implemented.
>
> It's not possible if you allow actual memory reuse! Now I'm not sure I  
> understand what you want.
>
> Andrei

In our custom memory management system, deallocated memory gets filled  
with a debug data, which is checked for consistency when memory gets  
allocated again. Any write to that memory we be noticed. Not immediately,  
but still, it's better than nothing. Microsoft C++ debug runtime does the  
same.

Under Windows (2000 and later) you can also mark a range of memory as not  
accessible (by calling VirtualProtect on that memory with a PAGE_NOACCESS  
flag). Any read/write attempt with cause an immediate access violation  
exception. This is not widely used, probably because it's slow, but when  
you have a memory damage (caused by modifying some memory via a dangling  
pointer) performance is of lesser importance.

I believe similar mechanisms exist for nixes, too.



More information about the Digitalmars-d mailing list