heap stack diagram
play

Heap-stack Diagram Sanzheng Qiao McMaster University November, - PowerPoint PPT Presentation

Sizes of Objects Generating Heap-stack Diagrams Example Heap-stack Diagram Sanzheng Qiao McMaster University November, 2011 Sizes of Objects Generating Heap-stack Diagrams Example Outline 1 Sizes of Objects 2 Generating Heap-stack


  1. Sizes of Objects Generating Heap-stack Diagrams Example Heap-stack Diagram Sanzheng Qiao McMaster University November, 2011

  2. Sizes of Objects Generating Heap-stack Diagrams Example Outline 1 Sizes of Objects 2 Generating Heap-stack Diagrams 3 Example

  3. Sizes of Objects Generating Heap-stack Diagrams Example Sizes of objects 1 byte char , bool 2 bytes short 4 bytes int , float 8 bytes long , double 16 bytes long double 1 byte = 8 bits

  4. Sizes of Objects Generating Heap-stack Diagrams Example Sizes of objects enumerated type ( enum ): 4 bytes structure type ( struct ): enough space for all individual fields, no overlap array: enough space for all elements, assigned consecutive locations pointer: 4 bytes Memory is byte addressable.

  5. Sizes of Objects Generating Heap-stack Diagrams Example Outline 1 Sizes of Objects 2 Generating Heap-stack Diagrams 3 Example

  6. Sizes of Objects Generating Heap-stack Diagrams Example Generating heap-stack diagrams Start with an empty diagram, heap and stack side by side. Heap expands towards larger memory addresses, starting say 1000, grows downward on page, allocate heap memory when new operator appears Stack builds towards smaller memory addresses, starting say FFFF, grows upward on page

  7. Sizes of Objects Generating Heap-stack Diagrams Example Generating heap-stack diagrams Manually trace the program, allocating memory as you go Add a new stack frame for each function call Use a shaded block as overhead to separate stack frames Spaces for all local variables (arguments, variables declared in the body, loop index), label the spaces Initialize the arguments Pop the stack frame when the function returns

  8. Sizes of Objects Generating Heap-stack Diagrams Example Outline 1 Sizes of Objects 2 Generating Heap-stack Diagrams 3 Example

  9. Sizes of Objects Generating Heap-stack Diagrams Example Example int main() { pointT pt; pt.x = 1; pt.y = 2; int *array = new int[3]; Nonsense(array, pt); return 0; } void Nonsense(int list[], pointT &ptr) { list[1] = ptr->x; } heap stack

  10. Sizes of Objects Generating Heap-stack Diagrams Example Example int main() { pointT pt; pt.x = 1; pt.y = 2; <----- diagram int *array = new int[3]; Nonsense(array, pt); return 0; } void Nonsense(int list[], pointT &ptr) { list[1] = ptr->x; } heap stack 1 pt FFF4 2 FFF8

  11. Sizes of Objects Generating Heap-stack Diagrams Example Example int main() { pointT pt; pt.x = 1; pt.y = 2; int *array = new int[3]; <----- diagram Nonsense(array, pt); return 0; } void Nonsense(int list[], pointT &ptr) { list[1] = ptr->x; } heap stack 1000 1004 array 1000 FFF0 1 pt FFF4 2 FFF8

  12. Sizes of Objects Generating Heap-stack Diagrams Example Example int main() { pointT pt; pt.x = 1; pt.y = 2; int *array = new int[3]; Nonsense(array, pt); return 0; } void Nonsense(int list[], pointT &ptr) { list[1] = ptr->x; <----- diagram } heap stack FFF4 1000 ptr FFE4 1000 1 1004 list FFE8 array 1000 FFF0 1 pt FFF4 2 FFF8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend