👾 Geek Engineers
539 subscribers
51 photos
42 files
330 links
👾 Extremist software engineering guidance for Geeks.

Website:
https://geekengineers.netlify.app

Github:
https://github.com/geekengineers
https://github.com/tahadostifam

Community:
@geek_engineers_community
Download Telegram
بلاخره یافتم بکگراند های عجیب غریبی که فرانت کار های خوب درست میکنند از کجا میاد/=

https://bgjar.com/
👎5👍1
با استفاده از پکیج flamegraph میتونید گراف pprof تون رو داشته باشید.

https://github.com/brendangregg/FlameGraph
New:

Purpose: Allocates memory for a value of a specific type and returns a pointer to that memory location.

Return type: Pointer to the allocated memory (e.g., *T).

Initialization: The allocated memory is zero-initialized. This means all bits in the memory are set to 0.

Usage: Creating pointers to simple value types like structs or integers, where you need to manually manage the memory.
Implementing custom data structures with manual memory management.

Example:
var p *int // Declares a pointer to an integer
p = new(int) // Allocates memory for an integer and assigns the pointer to p
*p = 42 // Dereferences the pointer and assigns the value 42 to the allocated memory
Make:

Purpose: Allocates and initializes memory for specific data structures like slices, maps, and channels.

Return type: The specific data structure type (e.g., []T, map[K]V, chan T).

Initialization: The allocated memory is initialized with default values depending on the data structure type :

- Slices: Empty slice with a nil pointer and capacity of 0.
- Maps: Empty map with a nil pointer.
- Channels: Unbuffered channel that can block operations until data is available or space becomes free.

Usage: Creating new instances of slices, maps, and channels for data storage and communication.

Example:
slice := make([]int, 5) // Creates a slice of integers with a capacity of 5 (can hold up to 5 elements)
myMap := make(map[string]string) // Creates an empty map to store string key-value pairs
ch := make(chan int) // Creates an unbuffered channel for integer communication
Differences between new and make in Go