Rust의 전체적인 그림 잡기

link


Stack & Heap 메모리 이해하기|🔝|

  • Stack은 고드름처럼 쌓여서 내려가고 Heap은 낮은 메모리 주소에 쌓여 들어간다.생각하면 됩니다. 낮은 메모리 주소에는 부팅에 필요한 코드 같은게 들어가니 충분히 공부한 후에 할당하세요.

    • Stack은 테트리스처럼 틈이 없이 쌓는 개념입니다.(embedded code에 사용되죠)
  • Stack과 Heap은 개발자가 옛날에 정한 약속 같은거라 왼쪽은 stack / 오른쪽은 heap하자 느낌으로 기억하자]()

  • 그림으로 이해해보자 RAM모양을 내 맘대로 정했다. 이게 외우기 젤 좋다.


  • stack vs heap
Stack vs Heap
컴파일 시간 결정
Stack is allocated at runtime;
layout of each stack frame,
however, is decided at compile time,
except for variable-size
arrays.
↓↓↓↓↓↓ Stack High memory 지역변수, 매개 변수 Local Varialble,
Parameter
↓↓↓↓↓↓ or ↑↑↑↑↑↑↑ Free Memory
Runtime 결정
A heap is a general term used for any memory
that is allocated dynamically and randomly;
i.e. out of order.
The memory is typically allocated by the OS.
with the application calling API functions
to do this allocation.
There is a fair bit of
overhead required in managing
dynamically allocated memory, which is
usually handled by the runtime code of
the programming language or
environment used.
↑↑↑↑↑↑↑ Heap Low Memory Heap
BSS
초기화 하지 않은
전역, 지역 변수(폐기된)
Uninitialized
discharge and local
variables.
Data
전역변수,정적 변수
Global Variable, Static Variable
Code
실행할 프로그램의 코드
The Code of the program to be executed.
Reserved

Stack buffer overflow[🔝]

stackOverFlowError란?[🔝]

  • 지정한 스택 메모리 사이즈보다 더 많은 스택 메모리를 사용하게 되어 에러가 발생하는 상황을 일컫는다.
    • 즉 스택 포인터가 스택의 경계를 넘어갈때 발생한다.
      • StackOverflowError 발생 종류
        • ① 재귀(Recursive)함수
        • ② 상호 참조
        • ③ 본인 참조
        • https://velog.io/@devnoong/JAVA-Stack-%EA%B3%BC-Heap%EC%97%90-%EB%8C%80%ED%95%B4%EC%84%9C#outofmemoryerror--java-heap-space-%EB%9E%80

Heap Overflow[🔝]

Stack vs Heap의 장점[🔝]

  • Stack
    • 매우 빠른 액세스
    • 변수를 명시적으로 할당 해제할 필요가 없다
    • 공간은 CPU에 의해 효율적으로 관리되고 메모리는 단편화되지 않는다.
    • 지역 변수만 해당된다
    • 스택 크기 제한(OS에 따라 다르다)
    • 변수의 크기를 조정할 수 없다

  • Heap
    • 변수는 전역적으로 액세스 할 수 있다.
    • 메모리 크기 제한이 없다
    • (상대적으로) 느린 액세스
    • 효율적인 공간 사용을 보장하지 못하면 메모리 블록이 할당된 후 시간이 지남에 따라 메모리가 조각화 되어 해제될 수 있다.
    • 메모리를 관리해야 한다 (변수를 할당하고 해제하는 책임이 있다)
    • 변수는 자바 new를 사용



Rust String VS 다른 언어의 String의 차이점|🔝|

111111

2222222 3333

물어보고 싶거나 하고 싶은말 써 주세요comment|🔝|