1.1. Understand computer storage and data types.
This objective may include but is not limited to: how a computer stores programs and the instructions in computer memory; memory stacks and heaps; memory size requirements for the various data storage types; numeric data and textual data.
Guiding
Questions
1.How are program instructions stored
in a computer?
2.Identify the different data types
that can be used and the values they can hold.
Activator
§Name
the components of a computer.
§What
components are involved in storing program instructions?
Review
Terms
§Data
type—a definition of a set of data that specifies the possible range of values
of the set, the operations that can be performed on the values, and the way in
which the values are stored in memory.
§Garbage
collection—a process for automatic recovery of heap memory.
§Heap—a
portion of memory reserved for a program to use for the temporary storage of
data structures whose existence or size cannot be determined until the program
is running.
§Memory
—a device where information can be stored and retrieved.
§Stack—a
region of reserved memory in which programs store status data such as procedure
and function call addresses, passed parameters, and sometimes local variables.
How a computer stores programs in memory
§A
computer keeps data and programs in storage as follows:
§Primary
storage—Otherwise known as random access memory (RAM), it is made of memory
chips. In common usage, it refers only to a computer’s main memory, the fast
semiconductor storage (RAM) directly connected to the processor.
§Secondary
storage—Otherwise known as a hard drive, it consists of a read/write head that
floats above rotating platters coated with a magnetic material.
Memory–Stacks
and Heaps
§Variables
are stored in either a stack or heapbased on their type:
§Value
types (e.g.: int,
double,
float)
go on the stack.
§Reference
types (String,
Object)
go on the heap.
* Value types in classes are stored with the
instance of the class on the heap.
The
stack
§Values
in the stack are managed without garbage collection because items are added and
removed from the stack as last in, first out (LIFO) every time you enter or
exit a scope, like a method or statement
A
StackOverFlowExceptionoccurs because you have used up all the available space in the stack.
Memory–Stacks
and Heaps (continued)
§The
heap
§A
heap-based memory allocation occurs when
we create a new object, at which point the compiler figures out how much memory
is needed and allocates an appropriate amount of memory space and returns a
reference representing the memory address.
§A
heap is used for dynamic allocation of memory.
§The
Microsoft .NET Framework uses garbage collection to free up space during run
time.
§Garbage
collection
is an automatic process for recovery of heap memory. Blocks of memory that had been allocated but
are no longer in use are freed, and blocks of memory still in use may be moved
to consolidate the free memory into larger blocks.
Data
Types
§Numeric
data types
§Integral
types (e.g.: byte, char, int)
§Floating-point
types (float,
double)
§Decimal
§Example: bool done
= false;
Decimal
Type
Using
the Numeric Data Types
byte numKids
= 15;
char letter = ‘p’;
int
worldPopulation
= 6692030277;
float money = 201.00f;
double lotsaMoney
= 2.4E+12;
decimal testGrade
= 89.5m;
Lesson
Review
§Describe
how the program statement below is stored in memory:
int
tennisPoints
= 30;
§Identify
the appropriate data types for each of the following values.
§4233423.93
§100
§-2323
§true
No comments:
Post a Comment