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

Support for read-only memory? #29

Open GerbenAbbink opened 2 years ago

GerbenAbbink commented 2 years ago

Is it possible to allocate memory with FastMM5 and make part of that memory read-only?

pleriche commented 2 years ago

Hi Gerben,

Unfortunately PC hardware only supports memory protection at the page level, which is 4096 bytes. You could allocate a block via FastMM and then call VirtualProtect to change the page the block is in to read-only mode, but you'll run into trouble if the adjacent blocks are written to by your application.

Alternatively you could allocate a 4K page via VirtualAlloc yourself, and then you can control the protection flags on that page without risk to adjacent blocks.

Best regards, Pierre

GerbenAbbink commented 2 years ago

Yes, that is what I wanted. Thank you.

On Sat, Jul 30, 2022 at 11:00 AM Pierre le Riche @.***> wrote:

Hi Gerben,

Unfortunately PC hardware only supports memory protection at the page level, which is 4096 bytes. You could allocate a block via FastMM and then call VirtualProtect to change the page the block is in to read-only mode, but you'll run into trouble if the adjacent blocks are written to by your application.

Alternatively you could allocate a 4K page via VirtualAlloc yourself, and then you can control the protection flags on that page without risk to adjacent blocks.

Best regards, Pierre

— Reply to this email directly, view it on GitHub https://github.com/pleriche/FastMM5/issues/29#issuecomment-1200120227, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCGIDYXFUS7YI2N3OVEJH3VWTVIRANCNFSM55C3GWLA . You are receiving this because you authored the thread.Message ID: @.***>