.\" Copyright (C) 2001 Andries Brouwer .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated 2002-04-14, HANATAKA Shinya .\" Updated 2003-07-03, Akihiro Motoki .\" Updated 2007-01-07, Akihiro MOTOKI, catch up to LDP v2.43 .\" .\"WORD: page ページ .\"WORD: legacy 過去の遺物 .\" .TH GETPAGESIZE 2 2007-07-26 "Linux" "Linux Programmer's Manual" .SH 名前 getpagesize \- メモリのページ・サイズを取得する .SH 書式 .B #include .sp .B int getpagesize(void); .sp .in -4n glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR getpagesize (): _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 .SH 説明 .BR getpagesize () 関数はページの大きさをバイト数で返す。ここでの「ページ」は .BR mmap (2) の説明の中で使用されているもので、 .BR mmap () はこのページサイズの単位でファイルをマップする。 .BR mmap (2) が使用するページサイズは以下のようにして知ることができる。 .in +4n .nf #include long sz = sysconf(_SC_PAGESIZE); .fi .in (ほとんどのシステムでは .B _SC_PAGESIZE の同義語として .B _SC_PAGE_SIZE を使用することができる)、もしくは以下のようにする: .in +4n .nf #include int sz = getpagesize(); .fi .in .\" .SH 歴史 .\" このシステムコールは 4.2BSD で初めて登場した。 .SH 準拠 SVr4, 4.4BSD, SUSv2. SUSv2 では .BR getpagesize () システムコールは「過去の遺物 (LEGACY)」とされており、 POSIX.1-2001 からは外されている。 HP-UX にはこのシステムコールは存在しない。 移植性が必要なアプリケーションでは、このシステムコールの代わりに .I sysconf(_SC_PAGESIZE) を利用すべきである。 .SH 注意 .BR getpagesize () が Linux のシステムコールとして存在するかどうかは、そのアーキテクチャに 依存している。 システムコールとして存在する場合には、カーネルシンボルの .B PAGE_SIZE を返す。 .B PAGE_SIZE の値は、アーキテクチャとマシンモデルに依存する。 一般に、バイナリは、アーキテクチャごとに1つのバイナリ配布で済ませるために、 アーキテクチャには依存しているがマシンモデルには依存していない。 つまり、ユーザプログラムはコンパイル時にヘッダーファイルから .B PAGE_SIZE を見つけて使用すべきではない。 少なくとも、マシンモデルについても依存性が存在する (sun4 のような) アーキテクチャにおいては本物のシステムコールを使用する必要がある。 尚、 libc4, libc5, glibc 2.0 では、 .BR getpagesize () がシステム・コールを使用せず、固定の値を返すために、この方法は 失敗する。glibc 2.1 では大丈夫である。 .SH 関連項目 .BR mmap (2), .BR sysconf (3)