LWN.net Logo

Short topics in memory management

Short topics in memory management

Posted Mar 7, 2007 16:50 UTC (Wed) by ibukanov (subscriber, #3942)
In reply to: Short topics in memory management by dion
Parent article: Short topics in memory management

> It would make a persistent cache a bit tricky,

The trick is to use relative offsets instead of pointers in the data that goes into the mapped file. It has an extra benefit of a more secure code since it is easier to add bound-check for the offsets then checking the pointers.


(Log in to post comments)

Short topics in memory management

Posted Mar 7, 2007 17:47 UTC (Wed) by zlynx (subscriber, #2285) [Link]

Checking offset bounds may look easier than a pointer, but it isn't really. A pointer is nothing but an offset from memory location 0, after all.

if( pointer > mmap_base && pointer < mmap_end ) ...

Using an unsigned int offset instead saves you from checking the lower bound, but you lose that savings again the instant you segment your memory into different uses, like using some for text and some for graphics.

Short topics in memory management

Posted Mar 8, 2007 23:57 UTC (Thu) by jzbiciak (✭ supporter ✭, #5246) [Link]

"A pointer is nothing but an offset from memory location 0, after all."

Well, these days it is on most architectures...

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds