Go conceptual memory model

I have a question for Go programmers among you. I can not find information about the details of the Go memory model. I will try to describe my problem:

If I declare and define a variable or array in C, I know that it exists somewhere in RAM in exactly the same position with one specific address, until I do something that will change this.

This does not apply to Python: Python does all the memory management for me, I cannot be sure that my data will always be in the same position. For instance. strings in practice are immutable, although the language suggests that this is not so. This makes safe programming with sensitive data virtually impossible (or at least very impractical).

My question is: how does Go work from this perspective. Is it more like C or like Python? Or is it completely different? Is it possible to process sensitive data as conveniently as in C?

+4
source share
2 answers

Note: as mentioned in the “ Go Slices: Usage and Internal Optionssection :

The representation [4]intin memory is just four integer values ​​laid out sequentially:

http://blog.golang.org/go-slices-usage-and-internals_slice-array.png

Go arrays are values .

; ( C). , , , .
( , , , .)

- , , : .

" ", .

- . , ( ).

s, make([]byte, 5), :

http://blog.golang.org/go-slices-usage-and-internals_slice-1.png

, , " "

Go , new make.
, , .

  • . , , , . new(T) T , *T.
    Go T.

  • make: make(T, args) , new(T). , ( ) T (not *T).
    , , .
    , , ( ), , , , .

. .

+6

, Go, , C Python. Go , Python, - , C. Go , Python. , .

Go . goroutine , . - Go , Java. ( .)

, , , , Go, C. ( ) , - . , , , .

Go, , , C. Go , C, . ( , Heartbleed.) Go, , .

+2

Source: https://habr.com/ru/post/1548192/


All Articles