how to know at compile time pagesize?

bioinfornatics bioinfornatics at fedoraproject.org
Sun Mar 11 22:38:55 PDT 2012


I would like use std.mmfile ang give to mmFile ctor a window.
For this i want to give value from getPagesize.
On my linux system in C i can do this.
_____________________
#include <unistd.h>
#include <stdio.h>

int main(){
int pageSize = getpagesize();
printf("Page size on your system = %i bytes\n", pageSize);
return 0;
}
_____________________

In D i have try this but do not build:

_____________________

import std.string;
import std.stdio;
import std.mmfile;

version(Windows){
    import std.parallelism;
    
    extern(Windows){ void GetSystemInfo(void*); }
    SYSTEM_INFO sysinfo;
    GetSystemInfo( &sysinfo );
    size_t win = sysinfo.dwAllocationGranularity;
}
else version(linux){
    import core.sys.posix.sys.shm;
    // extern(System) int getpagesize();    
    // size_t win = getpagesize();
    size_t win = SHMLBA;
}
else version( FreeBSD ){
    import core.sys.posix.sys.shm;
    size_t win = SHMLBA;
}
else
    static assert( false, "Not supported plateform");

void main(  ){
    witefln( "Page size: %d", win);
}

_____________________





More information about the Digitalmars-d-learn mailing list