glewis@cit-vax.Caltech.Edu (Glenn M. Lewis) (05/29/88)
[] What is the "acceptable" way to find out how much memory there is in the system from a C program (without AllocMem'ing until a failure)? I want to make a command that takes one argument, a memory size, and compares it to the amount of free memory available, and if there is more than the argument, it will return a "true" error code, so that I can test it with the AmigaDOS command "IF". (What is a boolean "true" error code in AmigaDOS, by the way?) Then, I can say in my startup sequence: IF FreeMemory 1Meg THEN Do_something_that_takes_a_lot_of_RAM Like_load_my_entire_SYS_disk_into_RAM or_Startup_TeX_-R_and_the_previewer ELSE Just_open_one_window_with_an_editor ENDIF Thanks. -- Glenn P.S. The reason I want to do this, for you that have been following my situation, is that I can't get 1.2 to work reliably in my ASDG 2M expansion RAM, even though it passes every RAM test I have found. I have been getting a lot of Layers Library (#03) Gurus lately, too. -- glewis@cit-vax.caltech.edu
papa@pollux.usc.edu (Marco Papa) (05/29/88)
In article <6743@cit-vax.Caltech.Edu> glewis@cit-vax.UUCP (Glenn M. Lewis) writes: | What is the "acceptable" way to find out how much memory there is |in the system from a C program (without AllocMem'ing until a failure)? | I want to make a command that takes one argument, a memory size, |and compares it to the amount of free memory available, and if there is more |than the argument, it will return a "true" error code, so that I can test |it with the AmigaDOS command "IF". (What is a boolean "true" error code |in AmigaDOS, by the way?) Then, I can say in my startup sequence: |IF FreeMemory 1Meg THEN | Do_something_that_takes_a_lot_of_RAM |ELSE | Just_open_one_window_with_an_editor |ENDIF There is a program that has been available since the Amiga inception called Availmem or Avail. I have seen the sources around 2 years ago, and it is probably on the FISH disks (Fred?). It wasn't as fancy as the one that is now included with AmigaDOS on the Workbench disk, but should be enough for your purpose. WARN is easy to use. "WARN is satisfied if the previous return code is |= 5" (from the AmigaDOS Users Manual). So make it return 0 in one case and 5 in the other one. The you'll have something like: MYAVAIL 1M IF WARN DO THIS ELSE DO THAT ENDIF Enjoy. -- Marco Papa 'Doc' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= uucp:...!pollux!papa BIX:papa ARPAnet:pollux!papa@oberon.usc.edu "There's Alpha, Beta, Gamma and Diga!" -- Leo Schwab [quoting Rick Unland] -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
mwm@eris.UUCP (06/01/88)
In article <6743@cit-vax.Caltech.Edu> glewis@cit-vax.UUCP (Glenn M. Lewis) writes:
< What is the "acceptable" way to find out how much memory there is
<in the system from a C program (without AllocMem'ing until a failure)?
Hmm - our wizards don't seem to be paying attention. Or maybe they
answered by mail.
Anyway, the call you want is AvailMem(int type). For example:
chip_free = AvailMem(MEMF_CHIP) >> 10;
fast_free = AvailMem(MEMF_FAST) >> 10;
give you the number of K free of each type of memory.
However, the amount of free memory and the largest chunk you can
allocmem are not the same. For instance, right now I've got 3.6 Meg
free, but can't get a chunk bigger than 2 Meg. The problem is that
free memory is at scattered locations through the memory spaces, but
AllocMem returns contigious memory blocks.
I've got a program (frags.c) that explains in gory detail how to walk
the free memory list. You're welcome to a copy of that, and tweaking
it to find the largest free chunk should be easy.
<mike
--
The weather is here, I wish you were beautiful. Mike Meyer
My thoughts aren't too clear, but don't run away. mwm@berkeley.edu
My girlfriend's a bore, my job is too dutiful. ucbvax!mwm
Hell nobody's perfect, would you like to play? mwm@ucbjade.BITNET
mwm@eris.UUCP (06/01/88)
In article <6743@cit-vax.Caltech.Edu> glewis@cit-vax.UUCP (Glenn M. Lewis) writes: < I want to make a command that takes one argument, a memory size, <and compares it to the amount of free memory available, and if there is more <than the argument, it will return a "true" error code, so that I can test <it with the AmigaDOS command "IF". (What is a boolean "true" error code <in AmigaDOS, by the way?) Almost forgot - I wrote that program for FAST memory quite a while back. It's short and simple, so here's a copy. <mike /* * fast-mem-p - exit 6 (WARN) if there is more K of fast mem than * the argument. Default is zero. * * Copyright (c) this? Are you kidding? * * Typical useage would be something like: * * fast-mem-p 2048 ; Have I got two meg or more of fast? * if warn * ; yes, do whatever setup you want here. * else * ; no, do small-time setup here. * endif * * For more power, (and more size), see "enough", on Fish disk 29. */ #include <exec/types.h> #include <exec/memory.h> void _main(argc, argv) char **argv; { register ULONG required ; ULONG AvailMem() ; required = (ULONG) (argc > 1 ? atoi(argv[1]) : 0) ; if ((AvailMem(MEMF_FAST) >> 10) > required) exit(6) ; exit(0) ; } -- So this is where the future lies Mike Meyer In a beer gut belly; In an open fly mwm@berkeley.edu Brilcreamed, acrylic, mindless boys ucbvax!mwm Punching, kicking, making noise mwm@ucbjade.BITNET