Chp 16: C Under Windows Flashcards
Microsoft categorizes the diff versions under 2 major heads. they?
Consumer Window:
For home, small offices.
Like: Windoes 95,98,ME.
Windows NT family:
For Business users.
Like: Windows NT, 2000, XP, Server 2003
Book refers to Windows NT.
Integers under 16 bit environment and 32 bit environment:
In 16 bit: Int is 2 bytes
32 bit envio : Int is 4 bytes.
range -2 147 483 648 to +2 147 483 647
If we want to store age, which doesn’t need 4 bytes at all then short int [2 bytes] used. Here Int and long int is the same.
typedefs USE:
- A windows program is required to perform plenty of complex tasks, perform I/O, send mails, play sound files…etc. Using normal int data type to represent variables that hold different entities we would soon lose track of what that integer value actually represents hence typedefine the integer as COLORREF, HANDLE, BOOL,..etc
- Typedefining long structure names.
Microsoft has done several typedefs for commonly used entities, all are stored in header files. These header files are provided as a part of 32-bit compiler like Visual C++.
Pointers in 32 bit World:
comment on how many tasks are allowed and how are allowed tasks managed?
In 16 bit envio only one task could be performed at a time so single-tasking envio, so all the resources of machine, like memory and hardware devices were accessible to this program.
In 32 bit envio several program reside and work in memory at same time, multi tasking environment.
To avoid the conflict of 2 programs, windows does not permit any application direct access to any machine resource. study in “Memory Management and Device Access”
Memory Management:
Users have become more demanding…
and windows run several applications simultaneously…
How does 16-bit envio do and how does 32 bit envio do?
16-bit envio allows max 1 MB which is too small for above. Hence windows evolved.
Windows run on 32-bit microprocessors so each CPU register is 32 bit long.
When we store a value at memory location the address of this location has to be stored in the register at some point of time. Thus 32 bit address can be stored in these registers and it leaves us with 2 raise 32 unique address choices. Which enables us to allow 4 GB of memory, and pointers who store these address become 4 byte entity.
If we decide to install 4 gb, it would cost a lot. So how does windows manage?
Windows uses a memory model which makes use of as much of physical memory(128 MB ish..) as has been installed and simulates the balanced amount of memory on the hard disk when the need to do so arises. This memory management is demand-based.
what do you think of the following sentence:
“ Programs are executed straight away from hard disk”
Programs are first brought into physical memory before they can get executed.
Page Out operation and Page In Operation:
Suppose there are multiple programs in memory and new one starts executing, if this needs more memory than available then some of existing programs(or their parts) are transferred to the disk in order to free the physical memory to accommodate new program.
This operation is called page out.
When the part of pragram which was paged out is needed is brought back to memory its called page in. These both keep on happening.
Page as in a block of memory ( 4096 bytes).
some rules sorta about page operations:
- Part of the program that is being executed can be paged out to disk.
- When it would be paged in again on need, its not necessary that it would page in at the same physical location.
Now, how do these paging operations affect our programming:
Pointer hold virtual address of location.
What is a virtual address?
Whats needed to get to an actual physical address.
this has 3 parts, these parts in conjunction with a CPU register (CR3) and contents of 2 tables Page directory and page table leads to an actual physical address.
how can we get to an actual physical address?
CR3 holds physical location of page directory table.
Left part of 32 bit virtual address holds index to page directory table, the value at index is starting address of page table.
Middle part is index into the page table, value at this index is starting address of the physical page in memory.
The right part holds byte offset(from start of the page) of the physical memory location to be accessed.
Can the actual address be reached by an application?
CR3 register is not accessible from an application, So no.
Also, as paging activity is going on the OS would suitably keep updating the values in the two tables.
Device Access:
All devices are shared among all running programs, so no program can access it directly.
Access is routed through device driver program, which finally accesses the device. more in chp 17 bout the std way.
These device drivers are to make sure no conflicts occur as many programs will want to access the device.
DOS programming Model:
16 bit program envio like DOS use sequential programming model. The path along which program flows from start to finish may vary during each execution depending on the inputs received or conditions under which it is run. However path remains predictable. Assume inputs to walk through program start to end.
C programs written in this model begin execution with main().
In this model the program and not the OS that decides which function will get called and when.