c++ - mmap: enforce 64K alignment -


i'm porting project written (by me) windows mobile platforms.

i need equivalent of virtualalloc (+friends), , natural 1 mmap. there 2 significant differences.

  1. addresses returned virtualalloc guaranteed multiples of so-called allocation granularity (dwallocationgranularity). not confused page size, number arbitrary, , on windows system 64k. in contrast address returned mmap guaranteed page-aligned.

  2. the reserved/allocated region may freed @ once call virtualfree, , there's no need pass allocation size (that is, size used in virtualalloc). in contrast munmap should given exact region size unmapped, i.e. frees given number of memory pages without relation how allocated.

this imposes problems me. while live (2), (1) real problem. don't want details, assuming smaller allocation granularity, such 4k, lead serious efficiency degradation. related fact code needs put information @ every granularity boundary within allocated regions, impose "gaps" within contiguous memory region.

i need solve this. can think pretty naive methods of allocating increased regions, can 64k-aligned , still have adequate size. or alternatively reserve huge regions of virtual address space, , allocating properly-aligned memory regions (i.e. implement sort of aligned heap). wonder if there alternatives. such special apis, maybe flags, secret system calls or whatever.

(1) quite easy solve. note, munmap takes size parameter, , because munmap capable of partial deallocation. can allocate chunk of memory bigger need, deallocate parts aren't aligned.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -