5_ada_acc_tyoes

5_ada_acc_tyoes - Introduction to Computers and Programming...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 5 Mar 29 2004 Today: Access Types Stack vs. Heap Allocating memory Deallocating memory Difference from C model Linked lists Dynamic Data Structures Arrays have disadvantages: size must be known at compile time space wasted or insufficient (overflow) inserting to/removing from middle requires shifting the elements Idea : Use dynamic, variable sized memory ( linked lists ) size starts at zero, changes as necessary space (de)allocated by programmer access variables needed Programs and Memory Stack : stores variables that are local to functions All static memory is allocated from the stack when a functions is called, its automatic variables are allocated on the top of the stack when it ends its variables are de-allocated Code Data Heap Stack Programs and Memory Heap : place for variables that are created with new and disposed by unchecked _ deallocation Dynamic memory is allocated from the heap Data : initalized variables including global and static variables Code (text): program instructions to be executed Code Data Heap Stack Programs and Memory Heap : place for variables that are created with new and disposed by unchecked _ deallocation Dynamic memory is allocated from the heap Data : initalized variables including global and static variables Code (text): program instructions to be executed Code Data Heap Stack Stack vs. Heap Stack Grows down Operations always take place at the top Push and pop are well organized Support for nested functions and recursion Heap Grows up The order in which objects are created or destroyed is completely under the control of the programmer You can have holes Dynamic memory management Memory fragmentation - memory fragments into small blocks over lifetime of program Node consists of item and pointer to next node Linked Lists Linked list : a list of nodes (records), each pointing to the next node List data type: insert/delete anywhere sequence of nodes implement using linked memory Singly linked list: head NULL signals end of list 42 98 12 6 List Operations Go to a position in the list. Insert : an item at a position in the list. Delete : an item from a position in the list. Retrieve : an item from a position. Replace : an item at a position. Traverse : a list. Search : for an item in the list. Storage allocation Allocator new T T is arbitrary data type memory is allocated for an object of type T pointer to that memory is returned new T'(value) memory allocated as above initial value stored in that memory pointer to the memory is returned examples: ?...
View Full Document

This note was uploaded on 01/28/2012 for the course AERO 16.01 taught by Professor Markdrela during the Fall '05 term at MIT.

Page1 / 11

5_ada_acc_tyoes - Introduction to Computers and Programming...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online