Go vs CPP

Go CPP
Memory Management Go has Automatic Garbage Collection, which means memory
allocation and deallocation are handled by the runtime
- goroutines are garbage collected.
CPP programmer has to do memory management using new, delete.
Structural Differences No hidden function as compared to c++

type ListNode struct {
    Val int
    Next *ListNode
}
                        
CPP have hidden functions, which can add overhead

class ListNode {
    int val;
    ListNode *next;
public:
    //constructor
    //destructor
};                            
                        
RunTime overhead Less More due to Exception handling, virtual function calls, and dynamic dispatch
Goroutine vs OS Threads Goroutines are faster wrt OS threads as implemented as Green threads by go runtime
Goroutine OS Thread
Memory Stack: Very small (~2 KB) and grows/shrinks dynamically
Heap: Descriptors tracked by the scheduler (~few hundred bytes each).
Fixed size, usually 1–2 MB (expensive)
Creation/Teardown Extremely fast; handled by the Go runtime. slow, call needed into kernel
Context Switching Fast. happens in user space (no kernel involvement) Slow. requires saving/restoring registers and entering kernel mode.
Scheduling M:N Scheduling: Thousands of goroutines(N) are multiplexed onto few OS threads(M). Managed by the OS kernel scheduler.
slower