align physical memory

Hi every one,

I would like to get physical address of share memory. My code likes this:

  1. Create a share memory using shm_open();
  2. Using shm_ctl() to set attribute of that share memory
  3. Map memory object by mmap();
  4. Get physical address of this memory by mem_offset();

My problem is that, the physical address is not align to the size of memory. How can I align this physical address?

For example:

  • memsize = 4KBytes, the physical address must be multiples of 0x1000
  • memsize = 8MBytes, the physical address must be multiples of 0x800000

Thanks.

Zodiac

You cannot. mmap/allocated bigger then you need and compensate yourself by setting the pointer to a multiple of what you need. That will waste memory but I don’t know of any other way.

Thanks Mario :slight_smile: