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.
addresses returned
virtualalloc
guaranteed multiples of so-called allocation granularity (dwallocationgranularity
). not confused page size, number arbitrary, , on windows system 64k. in contrast address returnedmmap
guaranteed page-aligned.the reserved/allocated region may freed @ once call
virtualfree
, , there's no need pass allocation size (that is, size used invirtualalloc
). in contrastmunmap
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
Post a Comment