Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site amiga.amiga.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!nsc!pyramid!amiga!bruceb From: bruceb@amiga.UUCP (Bruce Barrett) Newsgroups: net.micro.amiga Subject: Re: MMUs and program correctness Message-ID: <249@amiga.amiga.UUCP> Date: Thu, 14-Nov-85 12:56:56 EST Article-I.D.: amiga.249 Posted: Thu Nov 14 12:56:56 1985 Date-Received: Sat, 16-Nov-85 08:48:01 EST References: <862@nmtvax.UUCP> Reply-To: bruceb@hunter.UUCP (Bruce Barrett) Distribution: net Organization: Commodore-Amiga Inc., 983 University Ave #D, Los Gatos CA 95030 Lines: 37 Keywords: memory MMU Summary: How memory allocation is done In article <862@nmtvax.UUCP> you ask: > A few questions on this: does >the OS take care of memory allocation while a program is running, or >only when loading? For example, I write a quick sort in C that I want >to keep around in background. Every once in a while, I feed it source >and destination files, the program mallocs a bunch of space, sorts, >writes, then frees the space. When I call malloc, does the OS handle >it, or does the C compiler put in code to grab whatever looks good? >If the actual code is ~5k, and I read in 50k of data, will this cause >a problem? The answer is: The OS (AmigaDOS) allocates memory for code, data, and bss (uninitialized data) at the time your program is loaded. YOU have the option of declaring 50k of arrays within your program (very wasteful, not very flexible) --or-- requesting (and releasing) memory from the OS as you need it (much better). The memory you request can be either "chip" memory or "fast" memory. Chip memory is the memory that the custom VLSI chips have access to (0k to 512k). Fast memory is the other 8 meg (.5meg to 8.5meg). If there is not enough "fast" memory to satisfy your request (maybe you "only" have 512k of RAM) the system will allocate chip memory, if available. Remember that there is no contention between the VLSI chips and "Fast" memory. The choice is yours. The exec functions to use are "AllocMem" and "FreeMem". These are available from Assem and C. They allow you to specify memory type. The ROM Kernel Manual documents these. The 'C' runtime support uses "malloc", "calloc", "free", "getmem", "getml", "rlsmem", and "rlsml". I believe that they allocate "fast" memory. In any event they do NOT allow you to specify RAM type. The "Lattice C Compiler Manual" documents these. System calls (AvailMem) allow you to determine the total amount of free memory for any/all types, as well as the largest contiguous piece(s) available. -- Bruce Barrett