Free Essay

Os Concepts

In: Other Topics

Submitted By vinod7488
Words 9576
Pages 39
Memory Management in Mac OS

Memory Management in Mac OS
Mindfire Solutions www.mindfiresolutions.com March 6, 2002 Abstract: This paper discusses memory management by macintosh operating system. This paper is a summarized form of “Inside Macintosh: Memory” and is directed towards developers who are new to Mac development but had previous development experience on other operating system. After going through this article you will be familiar with memory architecture in Mac, ways to allocate and deallocate memory, using temporary memory, A5 world, heap management, heap zones, heap fragmentation and several other features provided by memory manager. MEMORY MANAGEMENT IN MAC OS.................................................................. 1 ORGANIZATION OF MEMORY IN MAC OS ......................................................... 3 The System Heap ..................................................................................................... 4 The System Global Variables................................................................................... 4 ORGANIZATION OF MEMORY IN AN APPLICATION PARTITION 1...................................... 4 The Application Stack 1........................................................................................... 6 The Application Heap 1........................................................................................... 6 The Application Global Variables and A5 World 1 .................................................. 7 TEMPORARY MEMORY 1 .............................................................................................. 8 VIRTUAL MEMORY 1.................................................................................................. 10 ADDRESSING MODES 1............................................................................................... 10 HEAP MANAGEMENT.................................................................................................. 10 Relocatable and Nonrelocatable Blocks 1.............................................................. 10 Properties of Relocatable Blocks 1 ........................................................................ 12 Locking and Unlocking Relocatable Blocks 1 ........................................................ 13 Purging and Reallocating Relocatable Blocks ....................................................... 13 MEMORY RESERVATION 1 .......................................................................................... 14 HEAP PURGING AND COMPACTION 1........................................................................... 14 HEAP FRAGMENTATION 1 ........................................................................................... 15 Deallocating Nonrelocatable Blocks 1................................................................... 15 Locking Relocatable Blocks 1................................................................................ 15 Allocating Nonrelocatable Blocks 1....................................................................... 16 DANGLING POINTERS 1............................................................................................... 16 Callback Routines 1............................................................................................... 17 INVALID HANDLES 1 .................................................................................................. 18 Disposed Handles 1............................................................................................... 18 info@mindfiresolutions.com Page 1 of 29

Memory Management in Mac OS

Empty Handles 1 ................................................................................................... 18 Fake Handles 1 ..................................................................................................... 18 LOW-MEMORY CONDITIONS....................................................................................... 19 Grow-Zone Functions 1......................................................................................... 19 SETTING UP THE APPLICATION HEAP .......................................................................... 19 Changing the Size of the Stack 1............................................................................ 19 Expanding the Heap 1 ........................................................................................... 20 Allocating Master Pointer Blocks 1 ....................................................................... 20 Defining a Grow-Zone Function 1 ......................................................................... 21 ABOUT THE MEMORY MANAGER ...................................................................... 21 TEMPORARY MEMORY 2 ............................................................................................ 21 INSTALLING A PURGE-WARNING PROCEDURE 2 .......................................................... 22 CREATING HEAP ZONES 2........................................................................................... 22 BLOCK HEADERS 2..................................................................................................... 23 VIRTUAL MEMORY 3.............................................................................................. 23 MEMORY MANAGEMENT UTILITIES ................................................................ 24 USING QUICKDRAW GLOBAL VARIABLES IN STAND-ALONE CODE 4 ........................... 24 THE A5 REGISTER 4 ................................................................................................... 25 ACCESSING THE A5 WORLD IN COMPLETION ROUTINES 4 ........................................... 26 ACCESSING THE A5 WORLD IN INTERRUPT TASKS 4 .................................................... 27

info@mindfiresolutions.com

Page 2 of 29

Memory Management in Mac OS

Organization of Memory in Mac OS
When the Macintosh Operating System starts up, it divides the available RAM into two broad sections. It reserves for itself a zone or partition of memory known as the system partition. The system partition always begins at the lowest addressable byte of memory (memory address 0) and extends upward. All memory outside the system partition is available for allocation to applications or other software components. In system software version 7.0 and later (or when MultiFinder is running in system software versions 5.0 and 6.0), the user can have multiple applications open at once. When an application is launched, the Operating System assigns it a section of memory known as its application partition. In general, an application uses only the memory contained in its own application partition. Fig: Memory organization in Mac with several applications open.

Source: Inside Macintosh: Memory

info@mindfiresolutions.com

Page 3 of 29

Memory Management in Mac OS

The System Heap
The main part of the system partition is an area of memory known as the system heap. In general, the system heap is reserved for exclusive use by the Operating System and other system software components, which load into it various items such as system resources, system code segments, and system data structures. All system buffers and queues, for example, are allocated in the system heap. Hardware device drivers (stored as code resources of type 'DRVR') are loaded into the system heap when the driver is opened.

The System Global Variables
The lowest part of memory is occupied by a collection of global variables called system global variables (or low-memory system global variables). The Operating System uses these variables to maintain different kinds of information about the operating environment. For example, the Ticks global variable contains the number of ticks (sixtieths of a second) that have elapsed since the system was most recently started up. Other low-memory global variables contain information about the current application. For example, the ApplZone global variable contains the address of the first byte of the active application’ partition. The ApplLimit global variable contains the address of s the last byte the active application’ heap can expand to include. The CurrentA5 s global variable contains the address of the boundary between the active application’ s global variables and its application parameters. Because these global variables contain information about the active application, the Operating System changes the values of these variables whenever a context switch occurs. Usually, when the value of a low-memory global variable is likely to be useful to applications, the system software provides a routine that you can use to read or write that value. For example, you can get the current value of the Ticks global variable by calling the TickCount function.

Organization of Memory in an Application Partition 1
When your application is launched, the Operating System allocates for it a partition of memory called its application partition. Your application partition is divided into three major parts: 1. the application stack 2. the application heap 3. the application global variables and A5 world

info@mindfiresolutions.com

Page 4 of 29

Memory Management in Mac OS

Fig: Organization of an application partition

Source: Inside Macintosh: Memory

The heap is located at the low-memory end of your application partition and always expands (when necessary) toward high memory. The A5 world is located at the highmemory end of your application partition and is of fixed size. The stack begins at the low-memory end of the A5 world and expands downward, toward the top of the heap. There is usually an unused area of memory between the stack and the heap. This unused area provides space for the stack to grow without encroaching upon the space assigned to the application heap. In some cases, however, the stack might grow into space reserved for the application heap. If this happens, it is very likely that data in the heap will become corrupted. The ApplLimit global variable marks the upper limit to which your heap can grow. If you call the MaxApplZone procedure at the beginning of your program, the heap immediately extends all the way up to this limit. If you were to use all of the heap’ free space, the Memory Manager would not allow you to allocate additional s blocks above ApplLimit. If you do not call MaxApplZone, the heap grows toward ApplLimit whenever the Memory Manager finds that there is not enough memory in the heap to fill a request. However, once the heap grows up to ApplLimit, it can grow no further. Thus, whether you maximize your application heap or not, you can use only the space between the bottom of the heap and ApplLimit. info@mindfiresolutions.com Page 5 of 29

Memory Management in Mac OS

Unlike the heap, the stack is not bounded by ApplLimit. If your application uses heavily nested procedures with many local variables or uses extensive recursion, the stack could grow downward beyond ApplLimit. Because you do not use Memory Manager routines to allocate memory on the stack, the Memory Manager cannot stop your stack from growing beyond ApplLimit and possibly encroaching upon space reserved for the heap. However, a vertical retrace task checks approximately 60 times each second to see if the stack has moved into the heap. If it has, the task, known as the “stack sniffer,” generates a system error. This system error alerts you that you have allowed the stack to grow too far, so that you can make adjustments.
Note: To ensure during debugging that your application generates this system error if the

stack extends beyond ApplLimit, you should call MaxApplZone at the beginning of your program to expand the heap to ApplLimit.

The Application Stack 1
The stack is an area of memory in your application partition that can grow or shrink at one end while the other end remains fixed. This means that space on the stack is always allocated and released in LIFO (last-in, first-out) order. The last item allocated is always the first to be released. It also means that the allocated area of the stack is always contiguous. Space is released only at the top of the stack, never in the middle, so there can never be any unallocated “holes” in the stack. By convention, the stack grows from high memory toward low memory addresses. The end of the stack that grows or shrinks is usually referred to as the “top” of the stack, even though it’ actually at the lower end of memory occupied by the stack. s When your application calls a routine, space is automatically allocated on the stack for a stack frame. A stack frame contains the routine’ parameters, local variables, and return s address.
Note: Dynamic memory allocation on the stack is usually handled automatically if you

are using a high-level development language such as Pascal. The compiler generates the code that creates and deletes stack frames for each function or procedure call.

The Application Heap 1
An application heap is the area of memory in your application partition in which space is dynamically allocated and released on demand. The heap contains virtually all items that are not allocated on the stack. For instance, your application heap contains the application’ code segments and resources that are currently loaded into memory. The s heap also contains other dynamically allocated items such as window records, dialog records, document data, and so forth.

info@mindfiresolutions.com

Page 6 of 29

Memory Management in Mac OS

The Memory Manager does all the necessary housekeeping to keep track of blocks in the heap as they are allocated and released. Because these operations can occur in any order, the heap doesn’ usually grow and shrink in an orderly way, as the stack does. Instead, t after your application has been running for a while, the heap can tend to become fragmented into a patchwork of allocated and free blocks. This fragmentation is known as heap fragmentation. One result of heap fragmentation is that the Memory Manager might not be able to satisfy your application’ request to allocate a block of a particular size. Even though there is s enough free space available, the space is broken up into blocks smaller than the requested size. When this happens, the Memory Manager tries to create the needed space by moving allocated blocks together, thus collecting the free space in a single larger block. This operation is known as heap compaction. Heap fragmentation is generally not a problem as long as the blocks of memory you allocate are free to move during heap compaction. There are, however, two situations in which a block is not free to move: when it is a nonrelocatable block, and when it is a locked, relocatable block.

The Application Global Variables and A5 World 1
Fig: Organization of an application’ A5 world s

Source: Inside Macintosh: Memory

info@mindfiresolutions.com

Page 7 of 29

Memory Management in Mac OS

Your application’ global variables are stored in an area of memory near the top of your s application partition known as the application A5 world. The A5 world contains four kinds of data: 1. application global variables 2. application QuickDraw global variables 3. application parameters 4. the application’ jump table s Each of these items is of fixed size, although the sizes of the global variables and of the jump table may vary from application to application. The system global variable CurrentA5 points to the boundary between the current application’ global variables and its application parameters. For this reason, the s application’ global variables are found as negative offsets from the value of s CurrentA5. This boundary is important because the Operating System uses it to access the following information from your application: its global variables, its QuickDraw global variables, the application parameters, and the jump table. This information is known collectively as the A5 world because the Operating System uses the microprocessor’ A5 register to point to that boundary. s Your application’ QuickDraw global variables contain information about its drawing s environment. For example, among these variables is a pointer to the current graphics port. Your application’ jump table contains an entry for each of your application’ routines s s that is called by code in another segment. The Segment Manager uses the jump table to determine the address of any externally referenced routines called by a code segment. The application parameters are 32 bytes of memory located above the application global variables; they’ reserved for use by the Operating System. The first long word of re those parameters is a pointer to your application’ QuickDraw global variables. s

Temporary Memory 1
In the Macintosh multitasking environment, each application is limited to a particular memory partition (whose size is determined by information in the 'SIZE' resource of that application). The size of your application’ partition places certain limits on the size s of your application heap and hence on the sizes of the buffers and other data structures that your application uses. In general, you specify an application partition size that is large enough to hold all the buffers, resources, and other data that your application is likely to need during its execution. If for some reason you need more memory than is currently available in your application heap, you can ask the Operating System to let you use any available memory that is not yet allocated to any other application. This memory, known as temporary memory, is allocated from the available unused RAM; usually, that memory is not contiguous with the memory in your application’ zone. s info@mindfiresolutions.com Page 8 of 29

Memory Management in Mac OS

Fig: Using temporary memory allocated from unused RAM

Source: Inside Macintosh: Memory

Your application should use temporary memory only for occasional short-term purposes that could be accomplished in less space, though perhaps less efficiently. For example, if you want to copy a large file, you might try to allocate a fairly large buffer of temporary memory. If you receive the temporary memory, you can copy data from the source file into the destination file using the large buffer. If, however, the request for temporary memory fails, you can instead use a smaller buffer within your application heap. One good reason for using temporary memory only occasionally is that you cannot assume that you will always receive the temporary memory you request. info@mindfiresolutions.com Page 9 of 29

Memory Management in Mac OS

Virtual Memory 1
In system software version 7.0 and later, suitably equipped Macintosh computers can take advantage of a feature of the Operating System known as virtual memory, by which the machines have a logical address space that extends beyond the limits of the available physical memory. It is important to realize that virtual memory operates transparently to most applications. Unless your application has time-critical needs that might be adversely affected by the operation of virtual memory or installs routines that execute at interrupt time, you do not need to know whether virtual memory is operating.

Addressing Modes 1
On suitably equipped Macintosh computers, the Operating System supports 32-bit addressing, that is, the ability to use 32 bits to determine memory addresses. Earlier versions of system software use 24-bit addressing, where the upper 8 bits of memory addresses are ignored or used as flag bits. When 32-bit addressing is in operation, the maximum program address space is 1 GB.

Heap Management
Relocatable and Nonrelocatable Blocks 1
You can use the Memory Manager to allocate two different types of blocks in your heap: nonrelocatable blocks and relocatable blocks. A nonrelocatable block is a block of memory whose location in the heap is fixed. In contrast, a relocatable block is a block of memory that can be moved within the heap (perhaps during heap compaction). To reference a nonrelocatable block, you can use a pointer variable, defined by the Ptr data type. A pointer is simply the address of an arbitrary byte in memory, and a pointer to a nonrelocatable block of memory is simply the address of the first byte in the block. Because a pointer is the address of a block of memory that cannot be moved, all copies of the pointer correctly reference the block as long as you don’ dispose of it. t The pointer variable itself occupies 4 bytes of space in your application partition. Often the pointer variable is a global variable and is therefore contained in your application’ s A5 world. But the pointer can also be allocated on the stack or in the heap itself. To reference relocatable blocks, the Memory Manager uses a scheme known as double indirection. The Memory Manager keeps track of a relocatable block internally with a master pointer, which itself is part of a nonrelocatable master pointer block in your application heap and can never move.

info@mindfiresolutions.com

Page 10 of 29

Memory Management in Mac OS

Note: The Memory Manager allocates one master pointer block (containing 64 master pointers) for your application at launch time, and you can call the MoreMasters procedure to request that additional master pointer blocks be allocated.

When the Memory Manager moves a relocatable block, it updates the master pointer so that it always contains the address of the relocatable block. You reference the block with a handle, defined by the Handle data type. A handle is a Memory Manager structure which is basically a pointer to a pointer (the first pointer is a handle, the second one is called a master pointer). Your code remembers the handle, and then, to resize it, the Memory Manager can free the master pointer and allocate new space anywhere in the heap. You allocate a handle using NewHandle and you release it using DisposeHandle. One of the most common times that you will use handles is when dealing with resources. All resources on the Macintosh are allocated as handles. You allocate a resource handle using GetResource and you release it using ReleaseResource or by closing the resource file. Fig: A pointer to a non relocatable block

Source: Inside Macintosh: Memory

info@mindfiresolutions.com

Page 11 of 29

Memory Management in Mac OS

Fig: A handle to a relocatable block

Source: Inside Macintosh: Memory

Master pointers for relocatable objects in your heap are always allocated in your application heap. Because the blocks of masters pointers are nonrelocatable, it is best to allocate them as low in your heap as possible. You can do this by calling the MoreMasters procedure when your application starts up. In some cases, however, you may be forced to allocate a nonrelocatable block of memory. When you call the Window Manager function NewWindow, for example, the Window Manager internally calls the NewPtr function to allocate a new nonrelocatable block in your application partition. Using relocatable blocks makes the Memory Manager more efficient at managing available space, but it does carry some overhead. As you have seen, the Memory Manager must allocate extra memory to hold master pointers for relocatable blocks.

Properties of Relocatable Blocks 1
If relocatable, a block can be either locked or unlocked; if it’ unlocked, a block can be s either purgeable or unpurgeable. These attributes of relocatable blocks can be set and changed as necessary

info@mindfiresolutions.com

Page 12 of 29

Memory Management in Mac OS

Locking and Unlocking Relocatable Blocks 1 To prevent a block from moving, you can lock it, using the HLock procedure. Once you have locked a block, it won’ move. Later, you can unlock it, using the Hunlock t procedure, allowing it to move again. In general, you need to lock a relocatable block only if there is some danger that it might be moved during the time that you read or write the data in that block. This might happen, for instance, if you dereference a handle to obtain a pointer to the data and (for increased speed) use the pointer within a loop that calls routines that might cause memory to be moved. If, within the loop, the block whose data you are accessing is in fact moved, then the pointer no longer points to that data; this pointer is said to dangle.
Note : Locking a block is only one way to prevent a dangling pointer.

Using locked relocatable blocks can, however, slow the Memory Manager down as much as using nonrelocatable blocks. The Memory Manager can’ move locked blocks. In t addition, except when you allocate memory and resize relocatable blocks, it can’ move t relocatable blocks around locked relocatable blocks (just as it can’ move them around t nonrelocatable blocks). Thus, locking a block in the middle of the heap for long periods of time can increase heap fragmentation. Locking and unlocking blocks every time you want to prevent a block from moving can become troublesome. Fortunately, the Memory Manager moves unlocked, relocatable blocks only at well-defined, predictable times. In general, each routine description in Inside Macintosh indicates whether the routine could move or purge memory. If you do not call any of those routines in a section of code, you can rely on all blocks to remain stationary while that code executes. Note that the Segment Manager might move memory if you call a routine located in a segment that is not currently resident in memory. Purging and Reallocating Relocatable Blocks By making a relocatable block purgeable, you allow the Memory Manager to free the space it occupies if necessary. If you later want to prohibit the Memory Manager from freeing the space occupied by a relocatable block, you can make the block unpurgeable. You can use the HPurge and HNoPurge procedures to change back and forth between these two states. A block you create by calling NewHandle is initially unpurgeable. Once you make a relocatable block purgeable, you should subsequently check handles to that block before using them if you call any of the routines that could move or purge memory. If a handle’ master pointer is set to NIL, then the Operating s System has purged its block. To use the information formerly in the block, you must reallocate space for it (perhaps by calling the ReallocateHandle procedure) and then reconstruct its contents (for example, by rereading the preferences file).

info@mindfiresolutions.com

Page 13 of 29

Memory Management in Mac OS

Fig: Purging and reallocating a relocatable block

Source: Inside Macintosh: Memory

Memory Reservation 1
The Memory Manager does its best to prevent situations in which nonrelocatable blocks in the middle of the heap trap relocatable blocks. When it allocates new nonrelocatable blocks, it attempts to reserve memory for them as low in the heap as possible. The Memory Manager reserves memory for a nonrelocatable block by moving unlocked relocatable blocks upward until it has created a space large enough for the new block. When the Memory Manager can successfully pack all nonrelocatable blocks into the bottom of the heap, no nonrelocatable block can trap a relocatable block, and it has successfully prevented heap fragmentation. During this process, the Memory Manager might even move a relocatable block over a nonrelocatable block to make room for another nonrelocatable block.

Heap Purging and Compaction 1
When your application attempts to allocate memory (for example, by calling either the NewPtr or NewHandle function), the Memory Manager might need to compact or purge the heap to free memory and to fuse many small free blocks into fewer large free blocks. The Memory Manager first tries to obtain the requested amount of space by compacting the heap; if compaction fails to free the required amount of space, the Memory Manager then purges the heap. When compacting the heap, the Memory Manager moves unlocked, relocatable blocks down until they reach nonrelocatable blocks or locked, relocatable blocks. You can compact the heap manually, by calling either the CompactMem function or the MaxMem function. info@mindfiresolutions.com Page 14 of 29

Memory Management in Mac OS

If you want, you can manually purge a few blocks or an entire heap in anticipation of a memory shortage. To purge an individual block manually, call the EmptyHandle procedure. To purge your entire heap manually, call the PurgeMem procedure or the MaxMem function.

Heap Fragmentation 1
Throughout this section, you should keep in mind the following rule: the Memory Manager can move a relocatable block around a nonrelocatable block (or a locked relocatable block) at these times only: When the Memory Manager reserves memory for a nonrelocatable block (or when you manually reserve memory before allocating a block), it can move unlocked, relocatable blocks upward over nonrelocatable blocks to make room for the new block as low in the heap as possible. When you attempt to resize a relocatable block, the Memory Manager can move that block around other blocks if necessary. In contrast, the Memory Manager cannot move relocatable blocks over nonrelocatable blocks during compaction of the heap.

Deallocating Nonrelocatable Blocks 1
One of the most common causes of heap fragmentation is also one of the most difficult to avoid. The problem occurs when you dispose of a nonrelocatable block in the middle of the pile of nonrelocatable blocks at the bottom of the heap. Unless you immediately allocate another nonrelocatable block of the same size, you create a gap where the nonrelocatable block used to be. If you later allocate a slightly smaller, nonrelocatable block, that gap shrinks. However, small gaps are inefficient because of the small likelihood that future memory allocations will create blocks small enough to occupy the gaps. It would not matter if the first block you allocated after deleting the nonrelocatable block were relocatable. The Memory Manager would place the block in the gap if possible. If you were later to allocate a nonrelocatable block as large as or smaller than the gap, the new block would take the place of the relocatable block, which would join other relocatable blocks in the middle of the heap, as desired. However, the new nonrelocatable block might be smaller than the original nonrelocatable block, leaving a small gap.

Locking Relocatable Blocks 1
Locked relocatable blocks present a special problem. When relocatable blocks are locked, they can cause as much heap fragmentation as nonrelocatable blocks. One solution is to reserve memory for all relocatable blocks that might at some point need to be locked, and to leave them locked for as long as they are allocated. This solution has drawbacks, however, because then the blocks would lose any flexibility that being relocatable otherwise gives them. Deleting a locked relocatable block can create a gap, just as deleting a nonrelocatable block can.

info@mindfiresolutions.com

Page 15 of 29

Memory Management in Mac OS

Fig: An effectively partitioned heap

Source: Inside Macintosh: Memory

Allocating Nonrelocatable Blocks 1
As you have seen, there are two reasons for not allocating nonrelocatable blocks during the middle of your application’ execution. First, if you also dispose of nonrelocatable s blocks in the middle of your application’ execution, then allocation of new s nonrelocatable blocks is likely to create small gaps, as discussed earlier. Second, even if you never dispose of nonrelocatable blocks until your application terminates, memory reservation is an imperfect process, and the Memory Manager could occasionally place new nonrelocatable blocks above relocatable blocks.

Dangling Pointers 1
Accessing a relocatable block by double indirection, through its handle instead of through its master pointer, requires an extra memory reference. For efficiency, you might sometimes want to dereference the handle— that is, make a copy of the block’ master s pointer— and then use that pointer to access the block by single indirection. When you do this, however, you need to be particularly careful. Any operation that allocates space from the heap might cause the relocatable block to be moved or purged. In that event, the block’ master pointer is correctly updated, but your copy of the master pointer is not. As s a result, your copy of the master pointer is a dangling pointer. Dangling pointers are likely to make your application crash or produce garbled output.

info@mindfiresolutions.com

Page 16 of 29

Memory Management in Mac OS

The easiest way to prevent dangling pointers is simply to lock the relocatable block whose data you want to read or write.

Callback Routines 1
Code segmentation can also lead to a different type of dangling-pointer problem when you use callback routines. The problem rarely arises, but it is difficult to debug. Some Toolbox routines require that you pass a pointer to a procedure in a variable of type ProcPtr. Ordinarily, it does not matter whether the procedure you pass in such a variable is in the same code segment as the routine that calls it or in a different code segment. For example, suppose you call TrackControl as follows: myPart := TrackControl(myControl, myEvent.where, @MyCallBack); If MyCallBack were in the same code segment as this line of code, then a compiler would pass to TrackControl the absolute address of the MyCallBack procedure. If it were in a different code segment, then the compiler would take the address from the jump table entry for MyCallBack. Either way, TrackControl should call MyCallBack correctly. Occasionally, you might use a variable of type ProcPtr to hold the address of a callback procedure and then pass that address to a routine. Here is an example: myProc := @MyCallBack; ... myPart := TrackControl(myControl, myEvent.where, myProc); As long as these lines of code are in the same code segment and the segment is not unloaded between the execution of those lines, the preceding code should work perfectly. Suppose, however, that myProc is a global variable, and the first line of the code is in a different segment from the call to TrackControl. Suppose, further, that the MyCallBack procedure is in the same segment as the first line of the code (which is in a different segment from the call to TrackControl). Then, the compiler might place the absolute address of the MyCallBack routine into the variable myProc. The compiler cannot realize that you plan to use the variable in a different code segment from the one that holds both the routine you are referencing and the routine you are using to initialize the myProc variable. Because MyCallBack and the call to TrackControl are in different code segments, the TrackControl procedure requires that you pass an address in the jump table, not an absolute address. Thus, in this hypothetical situation, myProc would reference MyCallBack incorrectly. To avoid this problem, make sure to place in the same segment any code in which you assign a value to a variable of type ProcPtr and any code in which you use that variable. If you must put them in different code segments, then be sure that you place the callback routine in a code segment different from the one that initializes the variable.
Note: Some development systems allow you to specify compiler options that force jump

table references to be generated for routine addresses. If you specify those options, the problems described in this section cannot arise. info@mindfiresolutions.com Page 17 of 29

Memory Management in Mac OS

Invalid Handles 1
An invalid handle refers to the wrong area of memory, just as a dangling pointer does. There are three types of invalid handles: empty handles, disposed handles, and fake handles.

Disposed Handles 1
A disposed handle is a handle whose associated relocatable block has been disposed of. When you dispose of a relocatable block (perhaps by calling the procedure DisposeHandle), the Memory Manager does not change the value of any handle variables that previously referenced that block. Instead, those variables still hold the address of what once was the relocatable block’ master pointer. Because the block has s been disposed of, however, the contents of the master pointer are no longer defined. (The master pointer might belong to a subsequently allocated relocatable block, or it could become part of a linked list of unused master pointers maintained by the Memory Manager.) You can avoid these problems quite easily by assigning the value NIL to the handle variable after you dispose of its associated block.

Empty Handles 1
An empty handle is a handle whose master pointer has the value NIL. When the Memory Manager purges a relocatable block, for example, it sets the block’ master s pointer to NIL. The space occupied by the master pointer itself remains allocated, and handles to the purged block continue to point to the master pointer. This is useful, because if you later reallocate space for the block by calling ReallocateHandle, the master pointer will be updated and all existing handles will correctly access the reallocated block.
Note: Don’ confuse empty handles with 0-length handles, which are handles whose t

associated block has a size of 0 bytes. A 0-length handle has a non-NIL master pointer and a block header.

Fake Handles 1
A fake handle is a handle that was not created by the Memory Manager. Normally, you create handles by either directly or indirectly calling the Memory Manager function NewHandle (or one of its variants, such as NewHandleClear). You create a fake handle— usually inadvertently— by directly assigning a value to a variable of type Handle, as illustrated in follwing listing.
Listing: Creating a fake handle

FUNCTION MakeFakeHandle: Handle; {DON’T USE THIS FUNCTION!} CONST kMemoryLoc = $100; {a random memory location} info@mindfiresolutions.com Page 18 of 29

Memory Management in Mac OS

VAR

Low-Memory Conditions
You can take several steps to help maximize the amount of free space in your heap. For example, you can mark as purgeable any relocatable blocks whose contents could easily be reconstructed. Before you call NewHandle or NewPtr, you should check that, if the requested amount of memory were in fact allocated, the remaining amount of space free in the heap would not fall below a certain threshold. The free memory defined by that threshold is your memory cushion.

Grow-Zone Functions 1
The Memory Manager provides a particularly easy way for you to make sure that the emergency memory reserve is released when necessary. You can define a grow-zone function that is associated with your application heap. The Memory Manager calls your heap’ grow-zone function only after other techniques of freeing memory to satisfy a s memory request fail (that is, after compacting and purging the heap and extending the heap zone to its maximum size). The grow-zone function can then take appropriate steps to free additional memory. A grow-zone function might dispose of some blocks or make some unpurgeable blocks purgeable. When the function returns, the Memory Manager once again purges and compacts the heap and tries to reallocate memory. If there is still insufficient memory, the Memory Manager calls the grow-zone function again (but only if the function returned a nonzero value the previous time it was called). This mechanism allows your grow-zone function to release just a little bit of memory at a time. If the amount it releases at any time is not enough, the Memory Manager calls it again and gives it the opportunity to take more drastic measures. As the most drastic step to freeing memory in your heap, you can release the emergency reserve.

Setting Up the Application Heap
To help prevent heap fragmentation, you should also perform some setup of your own early in your application’ execution. Depending on the needs of your application, you s might want to change the size of your application’ stack s expand the heap to the heap limit allocate additional master pointer blocks The following sections describe in detail how and when to perform these operations.

Changing the Size of the Stack 1
Most applications allocate space on their stack in a predictable way and do not need to monitor stack space during their execution. For these applications, stack usage usually reaches a maximum in some heavily nested routine. If the stack in your application can info@mindfiresolutions.com Page 19 of 29

Memory Management in Mac OS

never grow beyond a certain size, then to avoid collisions between your stack and heap you simply need to ensure that your stack is large enough to accommodate that size. If you never encounter system error 28 (generated by the stack sniffer when it detects a collision between the stack and the heap) during application testing, then you probably do not need to increase the size of your stack. To increase the size of your stack, you simply reduce the size of your heap. Because the heap cannot grow above the boundary contained in the ApplLimit global variable, you can lower the value of ApplLimit to limit the heap’ growth. By lowering ApplLimit, technically you are not making the s stack bigger; you are just preventing collisions between it and the heap. By default, the stack can grow to 8 KB on Macintosh computers without Color QuickDraw and to 32 KB on computers with Color QuickDraw. Listing below defines a procedure that increases the stack size by a given value. It does so by determining the current heap limit, subtracting the value of the extraBytes parameter from that value, and then setting the application limit to the difference.
Listing : Increasing the amount of space allocated for the stack

PROCEDURE IncreaseStackSize (extraBytes: Size); BEGIN SetApplLimit(Ptr(ORD4(GetApplLimit) - extraBytes)); END; You should call this procedure at the beginning of your application, before you call the MaxApplZone procedure.

Expanding the Heap 1
Near the beginning of your application’ execution, before you allocate any memory, you s should call the MaxApplZone procedure to expand the application heap immediately to the application heap limit. If you do not do this, the Memory Manager gradually expands your heap as memory needs require. This gradual expansion can result in significant heap fragmentation if you have previously moved relocatable blocks to the top of the heap (by calling MoveHHi) and locked them (by calling HLock). When the heap grows beyond those locked blocks, they are no longer at the top of the heap. Your heap then remains fragmented for as long as those blocks remain locked.

Allocating Master Pointer Blocks 1
After calling MaxApplZone, you should call the MoreMasters procedure to allocate as many new nonrelocatable blocks of master pointers as your application is likely to need during its execution. Each block of master pointers in your application heap contains 64 master pointers. The Operating System allocates one block of master pointers as your application is loaded into memory, and every relocatable block you allocate needs one master pointer to reference it.

info@mindfiresolutions.com

Page 20 of 29

Memory Management in Mac OS

Defining a Grow-Zone Function 1
The Memory Manager calls your heap’ grow-zone function only after other attempts to s obtain enough memory to satisfy a memory allocation request have failed. A grow-zone function should be of the following form: FUNCTION MyGrowZone (cbNeeded: Size): LongInt; The Memory Manager passes to your function (in the cbNeeded parameter) the number of bytes it needs. Your function can do whatever it likes to free that much space in the heap. PROCEDURE InitializeEmergencyMemory; BEGIN gEmergencyMemory := NewHandle(kEmergencyMemorySize); SetGrowZone(@MyGrowZone); END;

About the Memory Manager
The Memory Manager provides a large number of routines that you can use to perform various operations on blocks within your application partition. You can use the Memory Manager to set up your application partition allocate and release both relocatable and nonrelocatable blocks in your application heap copy data from nonrelocatable blocks to relocatable blocks, and vice versa determine how much space is free in your heap determine the location of the top of your stack determine the size of a memory block and, if necessary, change that size change the properties of relocatable blocks install or remove a grow-zone function for your heap obtain the result code of the most recent Memory Manager routine executed. The Memory Manager also provides routines that you can use to access areas of memory outside your application partition. You can use the Memory Manager to n allocate memory outside your partition that is currently unused by any open application or by the Operating System allocate memory in the system heap This section describes the areas of memory that lie outside your application partition. It also describes multiple heap zones.

Temporary Memory 2
In the Macintosh multitasking environment, your application is limited to a particular memory partition (whose size is determined by information in the 'SIZE' resource of your application). The size of your application’ partition places certain limits on the size s of your application heap and hence on the sizes of the buffers and other data structures that your application can use. If for some reason you need more memory than is currently available in your application heap, you can ask the Operating System to let you use any available memory that is not yet allocated to any other application. This memory, called temporary memory, is allocated from the available unused RAM; in general, that memory is not contiguous with the memory in your application’ zone Your application should use temporary memory s info@mindfiresolutions.com Page 21 of 29

Memory Management in Mac OS

only for occasional short-term purposes that could be accomplished in less space, though perhaps less efficiently.

Installing a Purge-Warning Procedure 2
You can define a purge-warning procedure that the Memory Manager calls whenever it is about to purge a block from your application heap. You can use this procedure to save the data in the block, if necessary, or to perform other processing in response to this notification.

Creating Heap Zones 2
You can create heap zones as subzones of your application heap zone or (in rare instances) either in space reserved for the application global variables or on the stack. You can also create heap zones in a block of temporary memory or within the system heap zone. This section describes how to create new heap zones by calling the InitZone procedure.
Listing : Creating a subzone of the original application heap zone

FUNCTION CreateSubZone: THz; CONST kZoneSize = 10240; {10K zone} kNumMasterPointers = 16; {num of master ptrs for new zone} VAR start: Ptr; {first byte in zone} limit: Ptr; {first byte beyond zone} BEGIN start := NewPtr(kZoneSize); {allocate storage for zone} IF MemError noErr THEN BEGIN {allocation successful} limit := Ptr(ORD4(start) + kZoneSize); {compute byte beyond end of zone} InitZone(NIL, kNumMasterPointers, limit, start); {initialize zone header, trailer} END; CreateSubZone := THz(start); {cast storage to a zone pointer} END;

info@mindfiresolutions.com

Page 22 of 29

Memory Management in Mac OS

Block Headers 2
Fig: A block header in a 32-bit zone

Source: Inside Macintosh: Memory

Every block in a heap zone, whether allocated or free, has a block header that the Memory Manager uses to find its way around in the zone. Block headers are completely transparent to your application. All pointers and handles to allocated blocks reference the beginning of the block’ logical contents, following the end of the header. Similarly, s whenever you use a variable of type Size, that variable refers to the number of bytes in the block’ logical contents, not including the block header. That size is known as the s block’ logical size, as opposed to its physical size, the number of bytes it actually s occupies in memory, including the header and any unused bytes at the end of the block.

Virtual Memory 3
A user can select (in the Memory control panel) whether to enable this larger or “virtual” address space. Most applications are completely unaffected by the operation of the Virtual Memory Manager and have no need to know whether any virtual memory is available. You might, however, need to intervene in the otherwise automatic workings of the Virtual Memory Manager if your application has critical timing requirements, executes code at interrupt time, or performs debugging operations. The Virtual Memory Manager extends the logical address space by using part of the available secondary storage (such as a hard disk) to hold portions of applications and data that are not currently in use in physical memory. When an application needs to operate on portions of memory that have been transferred to disk, the Virtual Memory Manager loads those portions back into physical memory by making them trade places with other, unused segments of memory. This process of moving portions (or pages) of memory between physical RAM and the hard disk is called paging. Users control and configure virtual memory through the Memory control panel. Controls in this panel allow the user to turn virtual memory on or off, set the size of virtual memory, and set the volume on which the invisible backing-store file resides. (The backing-store file is the file in which the Operating System stores the contents of nonresident pages of memory.) info@mindfiresolutions.com Page 23 of 29

Memory Management in Mac OS

Memory Management Utilities
Using QuickDraw Global Variables in Stand-Alone Code 4
If you are writing a stand-alone code segment such as a definition procedure for a window, menu, or control, you might want routines in that segment to examine the QuickDraw global variables of the current application. For example, you might want a control definition function to reference some of the QuickDraw global variables, such as thePort, screenBits, or the predefined patterns. Stand-alone segments, however, have no A5 world; if you try to link a stand-alone code segment that references your application’ global variables, the linker may be unable to resolve those references. To s solve this problem, you can have the definition function find the value of the application’ A5 register (by calling the SetCurrentA5 function) and then use that s information to copy all of the application’ QuickDraw global variables into a record in s the function’ own private storage. Listing below defines a record type with the same s structure as the QuickDraw global variables. Note that randSeed is stored lowest in memory and thePort is stored highest in memory.
Listing : Structure of the QuickDraw global variables

TYPE QDVarRecPtr = ^QDVarRec; QDVarRec = RECORD randSeed: LongInt; {for random-number generator} screenBits: BitMap; {rectangle enclosing screen} arrow: Cursor; {standard arrow cursor} dkGray: Pattern; {75% gray pattern} ltGray: Pattern; {25% gray pattern} gray: Pattern; {50% gray pattern} black: Pattern; {all-black pattern} white: Pattern; {all-white pattern} thePort: GrafPtr; {pointer to current GrafPort} END; The location of these variables is linker-dependent. However, the A5 register always points to the last of these global variables, thePort. The Operating System references all other QuickDraw global variables as negative offsets from thePort. Therefore, you must dereference the value in A5 (to obtain the address of thePort), and then subtract the combined size of the other QuickDraw global variables from that address. The difference is a pointer to the first of the QuickDraw global variables, randSeed. You can copy the entire record into a local variable simply by dereferencing that pointer, as illustrated in Listing below.
Listing : Copying the QuickDraw global variables into a record

info@mindfiresolutions.com

Page 24 of 29

Memory Management in Mac OS

PROCEDURE GetQDVars (VAR qdVars: QDVarRec); TYPE LongPtr = ^LongInt; BEGIN qdVars := QDVarRecPtr(LongPtr(SetCurrentA5)^ (SizeOf(QDVarRec) - SizeOf(thePort)))^; END; Thereafter, your stand-alone code segment can read QuickDraw global variables through the structure returned by GetQDVars. Listing below defines a very simple draw routine for a control definition function. After reading the calling application’ QuickDraw s global variables, the draw routine paints a rectangle with a pattern.
Listing : A control’ draw routine using the calling application’ QuickDraw patterns s s

PROCEDURE DoDraw (varCode: Integer; myControl: ControlHandle; flag: Integer); VAR cRect: Rect; qdVars: QDVarRec; origPenState: PenState; CONST kDraw = 1; {constant to specify drawing} BEGIN GetPenState(origPenState); {get original pen state} cRect := myControl^^.contrlRect; {get control’s rectangle} IF flag = kDraw THEN BEGIN GetQDVars(qdVars); {patterns are QD globals} PenPat(qdVars.gray); {install desired pattern} PaintRect(cRect); {paint the control} END; SetPenState(origPenState); {restore original pen state} END; The DoDraw drawing routine defined in Listing 4-6 retrieves the calling application’ s QuickDraw global variables and paints the control rectangle with a light gray pattern. It also saves and restores the pen state, because the PenPat procedure changes that state.

The A5 Register 4
If you write code that accesses your application’ A5 world (usually to read or write the s application global variables) at a time that your application is not the current application, you must ensure that the A5 register points to the boundary between your application’ s parameters and global variables. Because the Operating System accesses your A5 world relative to the address stored in the A5 register, you can obtain unpredictable results if you attempt to read or write data in your A5 world when the contents of A5 are not valid.

info@mindfiresolutions.com

Page 25 of 29

Memory Management in Mac OS

Accessing the A5 World in Completion Routines 4
Some Toolbox and Operating System routines require you to pass the address of an application-defined callback routine, usually in a variable of type ProcPtr. After a certain condition has been met, the Toolbox executes the specified routine. The exact time at which the Toolbox executes the routine varies. The timing of execution is determined by the Toolbox routine to which you passed the routine’ address and the s action that must be completed before the routine is called. Callback routines are quite common in the Macintosh system software. A grow-zone function, for instance, is an application-defined callback routine that is called every time the Memory Manager cannot find enough space in your heap to honor a memory-allocation request. Similarly, if your application plays a sound asynchronously, you can have the Sound Manager execute a completion routine after the sound is played. The completion routine might release the sound channel used to play the sound or perform other cleanup operations. In general, you cannot predict what your application will be doing when an asynchronous completion or callback routine is actually executed. The routine could be called while your application is executing code of its own or executing another Toolbox or Operating System routine.
Note: The completion or callback routine might even be called when your application is

in the background. Before executing a completion or callback routine belonging to your application, the Process Manager checks whether your application is in the foreground. If not, the Process Manager performs a minor switch to give your application temporary control of the CPU. Many Toolbox and Operating System routines do not need to access the calling application’ global variables, QuickDraw global variables, or jump table. As a result, s they sometimes use the A5 register for their own purposes. They save the current value of the register upon entry, modify the register as necessary, and then restore the original value on exit. As you can see, if one of these routines is executing when your callback routine is executed, your callback routine cannot depend on the value in the A5 register. This effectively prevents your callback routine from using any part of its A5 world. To solve this problem, simply use the strategy that the Toolbox employs when it takes over the A5 register: save the current value in the A5 register at the start of your callback procedure, install your application’ A5 value, and then restore the original value when s you exit. Listing below illustrates a very simple grow-zone function that uses this technique. It uses the SetCurrentA5 and SetA5 utilities to manipulate the A5 register.

4
Listing : A sample grow-zone function

FUNCTION MyGrowZone (cbNeeded: Size): LongInt; VAR theA5: LongInt; {value of A5 when function is called} BEGIN theA5 := SetCurrentA5; {remember current value of A5; install ours} info@mindfiresolutions.com Page 26 of 29

Memory Management in Mac OS

IF (gEmergencyMemory^ NIL) & (gEmergencyMemory GZSaveHnd) THEN BEGIN EmptyHandle(gEmergencyMemory); MyGrowZone := kEmergencyMemorySize; END ELSE MyGrowZone := 0; {no more memory to release} theA5 := SetA5(theA5); {restore previous value of A5} END; The function SetCurrentA5 does two things: it returns the current value in the A5 register, and it sets the A5 register to the value of the CurrentA5 low-memory global variable. This global variable always contains a value that points to the boundary between the current application’ parameters and its global variables. The MyGrowZone s function defined in Listing 4-1 calls SetCurrentA5 on entry to make sure that it can read the value of the gEmergencyMemory global variable. The function SetA5 also does two things: it returns the current value in the A5 register, and it sets the A5 register to whatever value you pass to the function. The MyGrowZone function calls SetA5 with the original value of the A5 register as the parameter. In this case, the value returned by SetA5 is ignored. There is no way to test whether, at the time your callback routine is called, your application is executing a Toolbox routine that could change the A5 register. Therefore, to be safe, you should save and restore the A5 register in any callback routine that accesses any part of your A5 world. Such routines include grow-zone functions Sound Manager completion routines n File Manager I/O completion routines control-action procedures TextEdit word-break and click-loop routines trap patches custom menu definition, window definition, and control definition procedures

Accessing the A5 World in Interrupt Tasks 4
Sometimes, an application-defined routine executes at a time when you can’ reliably call t SetCurrentA5. For example, if your application is not the current application and you call SetCurrentA5 as illustrated in Listing 4-1, the function will not return your application’ value of CurrentA5. The SetCurrentA5 function always returns the s value of the low-memory global variable CurrentA5, which always belongs to the current application. You’ end up reading some other application’ A5 world. ll s In general, you cannot reliably call SetCurrentA5 in any code that is executed in response to an interrupt, including the following: 1. Time Manager tasks 2. VBL tasks 3. tasks installed using the Deferred Task Manager 4. Notification Manager response procedures info@mindfiresolutions.com Page 27 of 29

Memory Management in Mac OS

Instead of calling SetCurrentA5 at interrupt time, you can call it at noninterrupt time when yours is the current application. Then store the returned value where you can read it at interrupt time. For example, the Notification Manager allows you to store information in the notification record passed to NMInstall. When you set up a notification record, you can use the nmRefCon field to hold the value in the A5 register. Listing below illustrates how to save the current value in the A5 register and pass that value to a response procedure.
Listing : Passing A5 to a notification response procedure

VAR gMyNotification: NMRec; {a notification record} BEGIN WITH gMyNotification DO BEGIN qType := ORD(nmType); {set queue type} nmMark := 1; {put mark in Application menu} nmIcon := NIL; {no alternating icon} nmSound := Handle(-1); {play system alert sound} nmStr := NIL; {no alert box} nmResp := @SampleResponse; {set response procedure} nmRefCon := SetCurrentA5; {pass A5 to notification task} END; END;

4
The key step is to save the value of CurrentA5 where the response procedure can find it— in this case, in the nmRefCon field. You must call SetCurrentA5 at noninterrupt time; otherwise, you cannot be certain that it will return the correct value. When the notification response procedure is executed, its first task should be to call the SetA5 function, which sets register A5 to the value stored in the nmRefCon field. At the end of the routine, the notification response procedure should call the SetA5 function again to restore the previous value of register A5. Listing below shows a simple response procedure that sets up the A5 register, modifies a global variable, and then restores the A5 register.
Listing : Setting up and restoring the A5 register at interrupt time

PROCEDURE SampleResponse (nmReqPtr: NMRecPtr); VAR oldA5: LongInt; {A5 when procedure is called} BEGIN oldA5 := SetA5(nmReqPtr^.nmRefCon); {set A5 to the application’s A5} gNotifReceived := TRUE; {set an application global } { to show alert was received} oldA5 := SetA5(oldA5); {restore A5 to original value} END; info@mindfiresolutions.com Page 28 of 29

Memory Management in Mac OS

Conclusion
After going through this article, you might have got a broad idea of what memory management in Mac alike and how it differs from the way other operating systems handles memory. For more insight into Mac memory management concepts and associated Toolbox routines refer to: http://developer.apple.com/techpubs/macos8/OSSvcs/MemoryManager/memorymanager. html

Mindfire Solutions is an IT and software services company in India, providing expert capabilities to the global market. Mindfire possesses experience in multiple platforms, and has built a strong track record of delivery. Our continued focus on fundamental strengths in computer science has led to a unique technology-led position in software services. To explore the potential of working with Mindfire, please drop us an email at info@mindfiresolutions.com. We will be glad to talk with you. To know more about Mindfire Solutions, please visit us on www.mindfiresolutions.com

info@mindfiresolutions.com

Page 29 of 29…...

Similar Documents

Premium Essay

Mac Os

... Here is a link to a PDF form where you can keep all your basic information. http://a248.e.akamai.net/7/248/51/3047521211216301/www.info.apple.com/images/ kbase/304752/my_mac_cheat_sheet.pdf This form can also be found on the last page of this handout. Switch 101 If you're a PC user who has just switched to the Mac and want to find out how to adapt your old working habits to the Mac OS, this is the right place. Visit Switch 101: The former PC user's guide to getting the most out of your Mac. Apple - Support - Switch 101 Mac Videos and Text Tutorials Apple - Find Out How - Mac Basics What is covered Mac Basics Photos Movies Web Music iWork MobileMe Mac Basics Apple - Find Out How - Mac Basics Videos tutorials available on Mac Basics Get Started with Mac (37) Anatomy of a Mac Move to Mac Windows on a Mac page 2 PC to Mac: The Basics Personalizing Your Mac Finder Basics Exposé Basics Using Safari iChat Basics Mail Basics Organizing Your Mail Wireless Wireless Basics Setting Up Your Wireless Network Wireless Printing, Backup, and More Streaming Music Wirelessly Going Further with Mac OS X Using the Sidebar Setting Up User Accounts page 3 Parental Controls Time Machine Basics Going Further with Mail Text tutorials Available on Mac Basics Customizing Your Mac Customize Your Mighty Mouse Customize Your Mac with a Screen Saver See Your Way Clear with Exposé Open Applications Automatically on Startup Quickly Switch Between Applications Get Dictionary Definitions......

Words: 2413 - Pages: 10

Free Essay

Os-Dos

...supervises the interaction between the system and its users. The OS also forms a base on which application software are developed and executed. “Some sort of layer of programs is required that will hide the complexity of the underlying hardware, manages all parts of the system and present the user with an interface. This layer or set of programs is the OS.” Functions of Operating System: 1. Command Interpretation 2. Peripheral Management 3. Run Time Memory Management 4. Disk Management 5. Process Management 6. Supervise the Computer System 7. Controlling input and output peripherals 8. Directing the flow of data 9. Maximize the use of hardware resources 10. To assure that number of programs can be run without human intervention 11. Scheduling and loading of programs 12. Provide appropriate response to the events 13. Handling errors and using corrective routines 14. Protecting hardware, software and data from improper use 15. Furnishing the complete records of all events and activities Types of Operating System Single-user OS: • • It is used for stand alone Computer (PC) It is further classified into two types: (1) Single-user Single-tasking (MS DOS) (2) Single-user Multi-tasking (MS Windows) Multi-user OS / Network Operation System: • • • It handles multiple users as well as multiple peripheral devices simultaneously. It also handles multiple tasks at the same time and therefore known as multi-user multi-tasking OS. Examples: UNIX, Linux, Windows (NT or Network......

Words: 2029 - Pages: 9

Free Essay

Breaktrhoughs in Os Technology

...The OS, or operating system, has long been a staple of the computer experience, but what aspect of these complex program sets have most attributed to this success? Having delved into this matter, I have concluded that the two aspects which most define this breakthrough popularity would be the GUI (Graphic User Interface) and the Touchscreen. The GUI Originally, a computer user would have to use a lot of command line instructions to launch programs. The introduction of the Graphic User Interface (GUI) changed that by replacing the command line controls for launching programs with icons on the screen, controlled by the mouse. The first “real” version of GUI was introduced to the masses in November of 1985 in the form of Windows 1.0. So what advantages did it offer? Well, for one thing, it allowed for the running of multiple applications or programs at once, a virtual first in the times of less advanced home computers. Now people could swap in and out of their most used or needed applications without excess command line input or closing out the current program and losing their data. This increased speed and productivity as well as making operating the PC much easier and user friendly for the mostly untrained populace. With this new advent, those who shunned the computer because of the heavy command coding needed to work it now had the option to use the newest technology in a way they could easily grasp. Consumers however, were not the only ones who reaped a benefit......

Words: 657 - Pages: 3

Free Essay

Os Study Guide

...COMP3361 Operating Systems I Mid-­term Review and Study Guide Basic Concepts: What is an operating system? A program that acts as an intermediary between a user of a computer and the computer hardware - basic functions? 1.) OS is a resource allocator 2.) manages all resources 3.) decides between conflicting requests for efficient and fair resource use 4.) OS is a control program 5.) controls execution of programs to prevent errors and improper use of the computer 6.) a program running at all times on the computer, usually called the kernel 7.)everything else is either a a.) system program: associated with the OS but not part of the kernel b.) application program: not associated with the OS user/kernel modes of operation? 1.) The operating system must ensure correct operation of the computer system. To prevent user programs from interfering with the proper operation of the system, the hardware has two modes: user mode and kernel mode. Various instructions (such as I/0 instructions and halt instructions) are privileged and can be executed only in kernel mode. 2.) Kernel Mode In Kernel mode, the executing code has complete and unrestricted access to the underlying hardware. It can execute any CPU instruction and reference any memory address. Kernel mode is generally reserved for the lowest-level, most trusted functions of the operating system. Crashes in kernel mode are catastrophic; they will halt the entire PC. 3.) User Mode In User......

Words: 2427 - Pages: 10

Premium Essay

Os and Utilities

...system software and identify the two types of system software Summarize the features of several stand-alone operating systems Describe the functions of an operating system Summarize the startup process on a personal computer Briefly describe various server operating systems Summarize the features of several embedded operating systems Explain the purpose of several utility programs See Page 397 for Detailed Objectives Discovering Computers 2012: Chapter 8 2 System Software • System software consists of the programs that control or maintain the operations of the computer and its devices Operating systems Page 398 Utility Programs Discovering Computers 2012: Chapter 8 3 Operating Systems • An operating system (OS) is a set of programs containing instructions that work together to coordinate all the activities among computer hardware resources Start and shut down a computer Coordinate tasks Provide a user interface Manage programs Establish an Internet connection Control a network Manage memory Configure devices Monitor performance Provide utilities Pages 398 - 399 Automatically update Administer security 4 Discovering Computers 2012: Chapter 8 Operating Systems Pages 398 – 399 Figure 8-1 Discovering Computers 2012: Chapter 8 5 Operating System Functions • The process of starting or restarting a computer is called booting Cold boot • Turning on a computer that has been powered off completely Page 400......

Words: 1834 - Pages: 8

Premium Essay

Open Closed Source Os

...share ideas and concepts that advance the development of mature and immature open source code is here to stay. The original hackers from the 1950’s (computer enthusiasts’) at MIT’s Tech Railroad Club left their programs in drawers for others to work on. This concept of sharing and developing source code for a wide range of functionality continues to enable programmers and students to use source code as a learning tool that sparks worldwide innovation! Open Source operating systems are usually free OS’s that can be manipulated via the source code format rather than the compiled binary code format, which is only available by closed source code. There are quite a few different open source code providers with the three most popular being GNU/Linux, BSD UNIX, and Solaris. Not only did the GNU/Linux open source operating system serve the standard OS features and function, it also produced many UNIX-compatible tools, including utilities, compilers and editors, but never released a kernel. The advantage of collaboration of the open source OS, Linus Torvalds, a student from Finland released a rudimentary UNIX-like kernel using the GNU compilers and tools and invented contributions worldwide. This is only one of the first examples of how the advantages of free software and open sourcing will continue to create, grow, and expand open source projects. These projects will continue to be shared between many individuals and companies, which will support the efforts and concepts of the GNU......

Words: 716 - Pages: 3

Premium Essay

Os Systems

...A proprietary system has to rely on the software and equipment it uses, which is licensed from a copyright. Therefore a proprietary operating system is specifically designed to work with each company that it is designed for, and nothing else. It is specific to their needs, and only that. Some examples are Windows and Mac OS X. A problem with this layout and design is that the system cannot be altered in any way; which is what can cause costly upgrades and repairs in the future, depending on the needs of the system and company that uses it. For the users that are not very technical, this is the better operating system to choose, since it is a lot easier to use. There are more options that are available as far as the settings for the system. Proprietary has more appeal to potential users, since it is specifically designed for each company individually. However can be more of a pain, since there aren’t the capabilities allowed to make changes within the system due to its design. Open Source Operating is cheaper, they don’t have to have licensing and also don’t require a specific format; unlike proprietary requires. An open source operating system does permit changes to be made, only after it is downloaded for the company that is using it. An example would be Linux that is used on a personal computer, or even Android for any mobile devices. . There are also more options that are available as far as the settings for the system, which do require more work to be involved. A......

Words: 858 - Pages: 4

Free Essay

Comparison of Some Os Booting

...(E), Aurangabad,Maharashtra, India. Email:amarmudiraj@gmail.com Abstract This paper presents a comparative study of Booting Paradigm of Windows, Linux and Mac, the three popular operating systems. Booting process is the essential and first step perform by the OS after this process execution all other processes can get the chance to execute , so we may say that booting is the first process because of which all other OS processes can execute. This experimental study gives an overview on the similarity and difference in Booting Process. As every operating system have to initially do the booting and as every OS providing different feature of each others, the paper is highlighting those micro and essential similarities and differences having by the operating systems during the Booting Process. Keywords: Booting, Cold booting, Worm booting, Linux Booting, Windows Booting, Mac Booting. In Worm Booting the computer get restart without shutdown the system, in which the system application and memory just get cleared and then reloading the operating system in primary memory. With the above two booting types we also have some other flavor in the computer booting like Sleep, Hibernate. Power - ON Load Instruction from ROM Detect OS from HDD 1. Introduction Find Attached H/W Booting Process is the first step gets happened in the computer system when you switch on the computer. In computing, booting is the initial set of operations that a computer system performs when electrical......

Words: 2846 - Pages: 12

Premium Essay

Mobile Os

... He is a coauthor of the textbook Database System Concepts. He has also written Op-Ed articles for the New York Times, the Boston Globe, and the Hartford Courant, among others. Peter Baer Galvin is the chief technologist for Corporate Technologies (www.cptech.com), a computer facility reseller and integrator. Before that, Mr. Galvin was the systems manager for Brown University's Computer Science Department. He is also Sun columnist for ;login: magazine. Mr. Galvin has written articles for Byte and other magazines, and has written columns for Sun World and SysAdmin magazines. As a consultant and trainer, he has given talks and taught tutorials on security and system administration worldwide. Greg Gagne is chair of the Computer Science department at Westminster College in Salt Lake City where he has been teaching since 1990. In addition to teaching operating systems, he also teaches computer networks, distributed systems, and software engineering. He also provides workshops to computer science educators and industry professionals. Operating systems are an essential part of any computer system. Similarly, a course on operating systems is an essential part of any computer-science education. This field is undergoing rapid change, as computers are now prevalent in virtually every application, from games for children through the most sophisticated planning tools for governments and multinational firms. Yet the fundamental concepts remain fairly clear, and it is on these that we......

Words: 403018 - Pages: 1613

Free Essay

Comparison of Opensource Os and Closed Source Os

...Comparison of open source OS and closed source OS Ted Wallick University of Phoenix The definition of closed source Operating System(OS), is any OS made but it's code and functionality is private to the vendor that made it. The end user can neither look at it's core/kernel or change it in any way. If an end user needs a change made, a change request has to be sent to the vendor to get adjustments made. This is how most commercial software is developed. Microsoft Windows OS (PC and mobile), Apple OS X, IOS, and UNIX, are primary examples of closed OS. Closed OS has some Pros and Cons. Pros: * Vendors have complete control over hardware and functionality. * The vendor gets to set some standards with how software and hardware are developed to work with the OS. * Vendor controls Versions and updates * Vendor controls any security issues (personally I would not want this hot potato) * Vendor has some control over what 3rd party developers make * Easier for the OS vendor and 3rd party developers to make money. Cons: * Response to system exploits (things that allow hackers to do whatever) is slower than open source OS due to a limited amount of code monkeys that have intimate knowledge and access to the OS code base * Closed OSs cost end users money hand over fist. Major upgrades will cost money. Most 3rd party software will cost large amounts of money. This is only fair to the people that put great time, effort and money to develop the......

Words: 976 - Pages: 4

Free Essay

Unix, Linux, Mac Os, Windows Os Comparison

...Introduction The most commonly known Operating Systems (OS) today are UNIX, Linux, MacOS, and Windows. These operating systems all behave in their own way and similar in others. This paper will discuss this comparison of how these operating systems utilize memory, process handling, file management, and security. Memory Management Each operating system is required to allocate a certain amount of memory for the operating system itself for the processes that are being used or executed. There are two places memory exists: physically on the motherboard of the computer and within the operating system itself. When the operating system dynamically divides the memory usage between these two areas, this is called memory management. Each operating system manages memory different from the others; however they all follow some basic rules of memory management. All of the operating system’s memory management in general follows these requirements: relocation, protection, sharing, logical organization, and physical organization (Stallings, 2015). Relocation of memory is the process that allows the operating system to move a process or file from physical memory to virtual memory and back again, depending on the need for that data. Virtual memory exists within the operating system which uses the hard drive to store temporary information and physical memory is located on the motherboard of the computer. While the process is in memory, protection of that area needs to be enabled to...

Words: 2918 - Pages: 12

Premium Essay

Os Comparison

...Comparison of Windows, Mac OS X and Linux Operating Systems Team A POS/355 March 6, 2015 Memory Management System Memory management is the process of allocating memory during your programs runtime. Memory Management in MAC OS is a multi-core and multi-processor execution that is supported and a programming API, which is called grand central dispatch. It is in the MAC OS. It provides a pool of available threads. There are ways to prevent memory related problems; Freeing data that is still in use, this can cause memory corruption that can result in your application crashing or worse corrupted user data. The MAC operating system can provide most concurrency as possible based on the number of cores available, and those threads depend on the capacity of the system. Windows memory management system is both physical and has virtual memory. It is mainly controlled by the virtual memory managers and pages. “Windows operating system operates on many platforms then it uses page sizes that can range between 4KB to 64KB. So this means that windows virtual memory can control how memory can allocate paging performance” (Stallings, 2013). Committed, Available, and Reserved are three types of regions of space or memory that the operating system can manage. Committed region is space it’s pages that have been stored either in physical or virtual memory. It also allows the process to access the virtual memory pages. Available region is where the address of the process is not being......

Words: 2964 - Pages: 12

Free Essay

Os History

...surge una gran variedad de sistemas operativos debido a que muchos de los fabricantes hacían que sus dispositivos móviles funcionaran con sistema diseñado solo para ellos. El nuevo milenio produjo grandes cambios en el mercado de los sistemas operativos aumentando en gran medida la competencia entre los diferentes desarrolladores siendo Windows, Unix y Mac OS los más competitivos, siempre buscando la facilidad y mejoramiento de recursos para el usuario. Y haciendo que estos se orienten a desarrollar para plataformas distribuidas y computación móvil e inalámbrica, y que cada vez más utilice el internet para sus diferentes fines. Un gran cambio se da en los microprocesadores, no solo por el paso de 32 bits a 64 bits, también por el uso de más de un núcleo tanto virtual como físico; lo que conlleva a que los nuevos sistemas operativos puedan dividir tareas en busca de una mayor velocidad y mejor manejo de datos, todo esto con la disminución de los precios en hardware ayuda a crear sistemas operativos impensables antes del 2000, pero claro mucho más robustos. El futuro apunta a sistemas operativos en la nube, llamados Web OS que actualmente están en desarrollo y donde no se requiere instalar software, solo tenemos que escoger el programa (“o aplicación web”) adecuado para realizar lo que queramos hacer, mediante conexión a internet y un navegador recibiendo la información o las solicitudes que nosotros queramos ya que el procesamiento estaría del otro lado, es decir del......

Words: 4031 - Pages: 17

Premium Essay

Android Os

...kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets. Android's user interface is mainly based on direct manipulation, using touch gestures that loosely correspond to real-world actions, such as swiping, tapping and pinching, to manipulate on-screen objects, along with a virtual keyboard for text input. In addition to touchscreen devices, Google has further developed Android TV for televisions, Android Auto for cars, and Android Wear for wrist watches, each with a specialized user interface. Variants of Android are also used on notebooks, game consoles, digital cameras, and other electronics. Android has the largest installed base of all operating systems of any kind. Android has been the best selling OS on tablets since 2013, and on smartphones it is dominant by any metric.[14][15] Initially developed by Android, Inc., which Google bought in 2005,[16] Android was unveiled in 2007 along with the founding of the Open Handset Alliance – a consortium of hardware, software, and telecommunication companies devoted to advancing open standards for mobile devices.[17] As of July 2013, the Google Play store has had over one million Android applications ("apps") published, and over 50 billion applications downloaded.[18] An April–May 2013 survey of mobile application developers found that 71% of developers create applications for Android,[19] and a 2015 survey found that 40% of full-time professional developers see Android as their priority......

Words: 275 - Pages: 2

Premium Essay

Os on the Web

...Common Internet Operating Systems POS/355 Joseph Lyon University of Phoenix July 10, 2012 There are a number of operating systems that are used on and for the internet. The most common operating systems used today are Microsoft, Linux, and Mac OS. Each of these offer different ways to view the internet (browser), as well as interact with other computer systems via the internet. Each of these operating systems has almost a cult following whose users are very good at them. The most commonly used OS would be the Microsoft line of operating systems. These started from Windows 3.1 and have evolved to the most recent Windows 8. These operating systems are the most commonly used due to the easy to use GUI and Microsoft has one of the largest software libraries out there. Most Companies use a mix of Microsoft and Linux server systems. The most commonly used version is currently Windows XP, but due to the drop of support, will soon be Windows 7. A large factor to the commonality of this OS is due to the gaming industry and social networking sites. With the increase of graphical complexity of games increasing exponentially, the operating systems needed to be more efficient in its utilization of resources. Then, tie in the MMORPG (Massive multiplayer online role playing game), and you need a system that can put graphics and online resources together to allow playability. Why play a game by yourself when you can play online with a huge player base. With the......

Words: 820 - Pages: 4

Kaleido Star | Honda Prelude type 1 (1982) oldtimer / collectorsitem | Visions enkellaarsjes