Sobes.tech
Junior — Middle

Kui suur on andmestruktuur ilma üksuste või andmeteta sees?

sobes.tech AI

Vastus AI-lt

In Go, an empty struct (struct without fields) occupies 0 bytes of memory. This is a language feature: an empty struct contains no data, so its size is zero.

Example:

package main

import (
	"fmt"
	"unsafe"
)

type Empty struct{}

func main() {
	var e Empty
	fmt.Println(unsafe.Sizeof(e)) // Will print 0
}

This is useful, for example, for creating a set using a map map[Empty]struct{}, where the value does not occupy additional memory.