www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Allocating aligned memory blocks?

reply "H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> writes:
Hi all,

I'm working on a very large associative array implementation that stores
most of the data on disk, and I need to allocate a number of cache areas
for keeping "hot" disk pages in RAM. Is there a way to allocate GC
memory blocks in D that are guaranteed to fall on OS page boundaries? Or
should I just forget the GC and just use posix_memalign() manually?

Thanks!


T

-- 
If creativity is stifled by rigid discipline, then it is not true creativity.
Dec 11 2014
parent reply "safety0ff" <safety0ff.dev gmail.com> writes:
On Friday, 12 December 2014 at 06:17:56 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:
 Is there a way to allocate GC
 memory blocks in D that are guaranteed to fall on OS page 
 boundaries?
I don't know about guarantees, I think that in practice, if your OS page size is 4096, any GC allocation of 4096 or greater will be page aligned.
 should I just forget the GC and just use posix_memalign() 
 manually?
I think it may be possible to do what you want with mmap/munmap alone (selectively map parts of the file to memory.)
Dec 11 2014
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 12/12/14 2:02 AM, safety0ff wrote:
 On Friday, 12 December 2014 at 06:17:56 UTC, H. S. Teoh via
 Digitalmars-d-learn wrote:
 Is there a way to allocate GC
 memory blocks in D that are guaranteed to fall on OS page boundaries?
I don't know about guarantees, I think that in practice, if your OS page size is 4096, any GC allocation of 4096 or greater will be page aligned.
Yes, it's how that will work, and I think it's de-facto guaranteed. Actually technically, you can allocate a block of 2049 or bigger, and it will allocate a page for it. -Steve
Dec 12 2014