1 / 29

ITEC 320

ITEC 320. Lecture 12 Higher level usage of pointers. Review. Linked list Pointer usage Package design. Problems. What are the major problems with pointers?. Reference counting. Each object has to be uniquely tracked in a system The number of pointers to that object is also counted

rafe
Download Presentation

ITEC 320

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 320 Lecture 12 Higher level usage of pointers

  2. Review • Linked list • Pointer usage • Package design

  3. Problems • What are the major problems with pointers?

  4. Reference counting • Each object has to be uniquely tracked in a system • The number of pointers to that object is also counted • Whenever a pointer is disposed, the reference count is decreased • What happens when it reaches 0? • What problem does this resolve?

  5. Smart pointers • Contain regular pointers • Also contain number of other pointers that are pointing to the object • Or do they… • What if an object contains the number of pointers to itself? • Benefits / downsides • Designs for this

  6. Factories • In your words, what are they?

  7. Approaches • Function that returns an object • Function that takes an object and returns a pointer • Function that takes an id and returns a pointer to it • Hash map for memory addresses and # of accesses • Others?

  8. Advantages/Disadvantages • Why use factories? • What do they mean for your code? • Benefits • Downsides

  9. Flyweight • What does the word bring to mind? • One object / pointer reused lots and lots of times • Similar to NULL except it is a type / pointer • What reasons do you think you would use a flyweight object? • Benefits / Downsides

  10. Disk buffer • How many GB does a DVD hold? • 3 DVD game • How does that game load everything into RAM? Or does it load everything into RAM? • Memory Mapping to HD idea

  11. How it works • Several blocks of data reserved in memory • Each block maps to a unique block on a HD • Data is requested, it is loaded from HD • If it is in list, use it, move to MRU position • If it isn’t, load into least recently used block and move it to the MRU position • Linked list of blocks?

  12. What it enables

  13. Design patterns • Not language specific features • Encompasses a particular idea • May or may not be heavily supported in a language • Java supports smart pointers by default • C++ requires a separate class • Not a silver bullet

  14. Command pattern • Signals when an action needs to be performed Command Central Contains pointers to objects Contains list of commands Told to execute X, it actually does it

  15. Cell phones • How do they work (communication side)

  16. Cell Networks

  17. Other scenarios • Computer networks • Google maps • Facebook friends • Gaming

  18. Rationale • How do you model a cell phone network on a computer? • Why would you want to simulate a cell phone network?

  19. Graphs • Composed of vertices and edges • Vertices • Represent an object in a graph • Edges • A connection between two vertices

  20. Variations • Weighted graph • Toll road • Hotel cost • Identifiers • Possible usage scenarios?

  21. Methods of implementation • Arrays • Pointers • Benefits of each approach • Downsides of each approach

  22. Code • Should we use a package? • What about generics?

  23. Searching • How do you find information in a graph? Start Destination

  24. Breadth first • For each node I am connected to • Is this the node I’m looking for? • If I didn’t find it • For each node I am connected to • Call breadth first search on it

  25. Depth first • If I am the node searched for, stop and return • For each node I am connected to • Call depth first search on that node

  26. Issues • What are some of the issues that might happen with searching? • How do you implement each way? • Stacks / Recursion / Packages / ?

  27. More • How do you pick the best path? • Lowest cost • Highest cost • Cover all points with least overlap

  28. Summary • Rationale for graph theory • Approach • Finding algorithms

  29. Summary • Memory usage at a higher level

More Related