pleriche / FastMM5

FastMM is a fast replacement memory manager for Embarcadero Delphi applications that scales well across multiple threads and CPU cores, is not prone to memory fragmentation, and supports shared memory without the use of external .DLL files.
283 stars 73 forks source link

Different debug patterns for allocated and freed memory #54

Closed janrysavy closed 2 weeks ago

janrysavy commented 3 weeks ago

Thank you for implementing FastMM_BeginEraseFreedBlockContent - it works great!

Could you please use a different pattern for allocated and freed memory? For reference, the Microsoft C++ debug runtime uses $CDCDCDCD for allocated memory and $DDDDDDDD for freed memory. You can find more details here: https://en.wikipedia.org/wiki/Magic_number_(programming)#Debug_values

pleriche commented 3 weeks ago

Thank you for the positive feedback.

Unfortunately I wasn't aware of the pattern that Microsoft was using back in 2004, so I went with the $80808080 pattern. It's probably a bit late in the game to change the value now, since users are already accustomed to it.

However, there isn't currently an option to pre-fill allocated blocks with a pattern and it would be possible to add such an option. I could use a different pattern for that, perhaps $81818181 (so it is somewhat similar to the pattern for freed blocks). Would that work for you?

janrysavy commented 3 weeks ago

Isn't FillDebugBlockWithDebugPattern called during allocations such as FastMM_DebugGetMem_GetDebugBlock?

Any solution is good for us.

pleriche commented 3 weeks ago

Ah yes, you're right. I forgot about that. So basically you want it to use a different pattern in FastMM_DebugGetMem_GetDebugBlock?

Edit: It's only currently available in debug mode. Do you need a feature similar to FastMM_BeginEraseFreedBlockContent.

janrysavy commented 3 weeks ago

We just would like to distinguish whether it is allocated or released memory by different constant. Debug mode only is fine for us, we are using it in our internal brief & full debug builds.

pleriche commented 3 weeks ago

I've changed the fill pattern for allocated blocks to $90909090. Please test the latest commit and let me know if it works for you.

janrysavy commented 2 weeks ago

Hello Pierre, thank you, it works perfectly.

I would like to return to your proposal to introduce an equivalent to FastMM_BeginEraseFreedBlockContent, but for allocated blocks. The memory fill is very fast, and we could use it permanently turned on, while the debug mode is computationally much more demanding. Would it be possible to add this mode as well?

pleriche commented 2 weeks ago

I've added FastMM_BeginEraseAllocatedBlockContent and FastMM_EndEraseAllocatedBlockContent calls. When enabled it will fill newly allocated blocks with the $90909090 pattern.

janrysavy commented 2 weeks ago

Thank you.