Is swap really needed when RAM's aplenty

Jussi Lehtola jussilehtola at fedoraproject.org
Fri Aug 20 19:00:31 UTC 2010


On Fri, 20 Aug 2010 13:22:33 -0500 (CDT)
Michael Hennebry <hennebry at web.cs.ndsu.nodak.edu> wrote:
> It makes sense that if a process insists on physically
> contiguous memory and can't get it, the process would die,
> but the above code does not tell the compiler what is to be achieved.
> 
> In the following, would fred or greg necessarily
> refer to physically contiguous memory?
> 
> #include <stdlib.h>
> extern void hank(char *);
> 
> int main(*args[], int argsNum)
> {
> char fred[69000];
> char *greg=malloc(96000);
> hank(fred);
> hank(greg);
> return 0;
> }

If I remember my Kerningham-Ritchie correctly, the answer is yes, since
C relies on pointer arithmetic to refer to the elements of the array.
The "fred" and "greg" variables are pointers to the beginning of the
corresponding memory area, and referring fred[i] goes to the start of
the array at fred, and then goes i elements forward to end up with the
wanted element.
-- 
Jussi Lehtola
Fedora Project Contributor
jussilehtola at fedoraproject.org


More information about the users mailing list