Ramon
Ramon

Reputation: 8424

How to constrain malloc to a specific region of memory

Is there anything that:

I can't think of a way of doing this with standard memory allocation functions. The only strategy that comes to mind is using a custom memory pool instead of malloc. So my question is: is there a way to do this without a custom malloc or (if there isn't) suggestions on what to use?

I could wrap malloc and keep track of all pages it has used pretty easily how do I guarantee that once I have called mprotect on these pages malloc doesn't try to use memory that is "caught" either before the start or after the end of an allocated block within one of the affected pages?

Upvotes: 1

Views: 806

Answers (1)

rptb1
rptb1

Reputation: 480

The open source Memory Pool System will allocate memory in operating system page-sized chunks which the MPS does not itself touch. You can mprotect these pages if you like and be certain that they won't be touched by the allocator itself (which keeps all its data structures elsewhere) or by any other memory pool. If you use the MVT pool class you can also take advantage on inline lockless allocation as well. Linux, Mac OS X, and Windows are supported.

Disclaimer: I'm the architect of the MPS.

Upvotes: 1

Related Questions