Determining system memory
der Mouse
mouse at mcgill-vision.UUCP
Wed Apr 13 07:20:29 AEST 1988
In article <248 at lxn.UUCP>, chris at lxn.UUCP (Christopher D. Orr) writes:
> I have been trying to find a nice, clean way to determine system
> memory under SYS V 2.2.
> Solution 2: [This is faster than Solution 1, but still slow]:
[program]
Well, you could speed it up by doing a more intelligent search
technique than linear search:
/****** UNTESTED (no SV system to test it on) ******/
#include <stdio.h>
#include <fcntl.h>
extern int errno;
static char buf;
main()
{
long int l;
long int m;
long int h;
int fd;
fd = open("/dev/mem",O_RDONLY);
/* check for fd<0 omitted for brevity */
l = 1;
h = 2;
while (1)
{ lseek(fd,h,L_SET); /* or whatever the SV way is */
if (read(fd,&buf,1) != 1) break;
l = h;
h *= 2;
}
while (h-l > 1)
{ m = (h + l) / 2;
lseek(fd,m,L_SET); /* or whatever */
if (read(fd,&buf,1) == 1) l = m; else h = m;
}
printf("%ld bytes accessible via /dev/mem\n",h);
exit(0);
}
der Mouse
uucp: mouse at mcgill-vision.uucp
arpa: mouse at larry.mcrcim.mcgill.edu
More information about the Comp.unix.questions
mailing list