github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/pkg/unsafe/unsafe.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  /*
     6  	Package unsafe contains operations that step around the type safety of Go programs.
     7  */
     8  package unsafe
     9  
    10  // ArbitraryType is here for the purposes of documentation only and is not actually
    11  // part of the unsafe package.  It represents the type of an arbitrary Go expression.
    12  type ArbitraryType int
    13  
    14  // Pointer represents a pointer to an arbitrary type.  There are four special operations
    15  // available for type Pointer that are not available for other types.
    16  //	1) A pointer value of any type can be converted to a Pointer.
    17  //	2) A Pointer can be converted to a pointer value of any type.
    18  //	3) A uintptr can be converted to a Pointer.
    19  //	4) A Pointer can be converted to a uintptr.
    20  // Pointer therefore allows a program to defeat the type system and read and write
    21  // arbitrary memory. It should be used with extreme care.
    22  type Pointer *ArbitraryType
    23  
    24  // Sizeof returns the size in bytes occupied by the value v.  The size is that of the
    25  // "top level" of the value only.  For instance, if v is a slice, it returns the size of
    26  // the slice descriptor, not the size of the memory referenced by the slice.
    27  func Sizeof(v ArbitraryType) uintptr
    28  
    29  // Offsetof returns the offset within the struct of the field represented by v,
    30  // which must be of the form structValue.field.  In other words, it returns the
    31  // number of bytes between the start of the struct and the start of the field.
    32  func Offsetof(v ArbitraryType) uintptr
    33  
    34  // Alignof returns the alignment of the value v.  It is the maximum value m such
    35  // that the address of a variable with the type of v will always be zero mod m.
    36  // If v is of the form structValue.field, it returns the alignment of field f within struct object obj.
    37  func Alignof(v ArbitraryType) uintptr