当前位置: 首页>>代码示例>>Golang>>正文


Golang C.size_t函数代码示例

本文整理汇总了Golang中C.size_t函数的典型用法代码示例。如果您正苦于以下问题:Golang size_t函数的具体用法?Golang size_t怎么用?Golang size_t使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了size_t函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ResizeWithFilter

// Changes the size of the canvas using specified filter and blur, returns true on success.
func (self *Canvas) ResizeWithFilter(width uint, height uint, filter uint, blur float32) error {
	if width == 0 && height == 0 {
		return errors.New("Please specify at least one of dimensions")
	}

	if width == 0 || height == 0 {
		origHeight := uint(C.MagickGetImageHeight(self.wand))
		origWidth := uint(C.MagickGetImageWidth(self.wand))

		if width == 0 {
			ratio := float32(origHeight) / float32(height)
			width = uint(float32(origWidth) / ratio)
		}
		if height == 0 {
			ratio := float32(origWidth) / float32(width)
			height = uint(float32(origHeight) / ratio)
		}
	}

	success := C.MagickResizeImage(self.wand, C.size_t(width), C.size_t(height), C.FilterTypes(filter), C.double(blur))

	if success == C.MagickFalse {
		return fmt.Errorf("Could not resize: %s", self.Error())
	}

	return nil
}
开发者ID:phacops,项目名称:canvas,代码行数:28,代码来源:canvas.go

示例2: Shuffle

func Shuffle(rng *rng.GslRng, data interface{}, n int) {
	// data must be a slice
	dataType := reflect.TypeOf(data)
	if dataType.Kind() != reflect.Slice {
		gogsl.Error("rng.Shuffle() must have a slice as its second argument", gogsl.GSL_EINVAL)
		return
	}
	baseType := dataType.Elem()
	dataVal := reflect.ValueOf(data)
	sliceN := dataVal.Len()
	if sliceN < 0 {
		gogsl.Error("shuffle length may not be negative in rng.Shuffle()", gogsl.GSL_EINVAL)
		return
	}
	if sliceN < n {
		gogsl.Error("shuffle length too large for slice in rng.Shuffle()", gogsl.GSL_EINVAL)
		return
	}
	elementLen := baseType.Size()
	addr := dataVal.Index(0).UnsafeAddr()

	//hdr := (*reflect.SliceHeader)(unsafe.Pointer(addr))
	//void gsl_ran_shuffle (const gsl_rng * r, void * base, size_t n, size_t size)
	C.gsl_ran_shuffle((*C.gsl_rng)(unsafe.Pointer(rng.Ptr())),
		unsafe.Pointer(addr),
		C.size_t(n), C.size_t(elementLen))
}
开发者ID:postfix,项目名称:gsl-1,代码行数:27,代码来源:randist_support.go

示例3: Conv

// Use the codec to convert a string
func (cd *Iconv) Conv(input string) (result string, err error) {
	var buf bytes.Buffer

	if len(input) == 0 {
		return "", nil
	}

	inbuf := []byte(input)
	outbuf := make([]byte, bufSize)
	inbytes := C.size_t(len(inbuf))
	inptr := &inbuf[0]

	for inbytes > 0 {
		outbytes := C.size_t(len(outbuf))
		outptr := &outbuf[0]
		_, err = C.iconv(cd.pointer,
			(**C.char)(unsafe.Pointer(&inptr)), &inbytes,
			(**C.char)(unsafe.Pointer(&outptr)), &outbytes)
		buf.Write(outbuf[:len(outbuf)-int(outbytes)])
		if err != nil && err != syscall.E2BIG {
			return buf.String(), err
		}
	}

	return buf.String(), nil
}
开发者ID:echou,项目名称:go-iconv,代码行数:27,代码来源:iconv.go

示例4: ReadAt

func ReadAt(fd int, off int64, size int) ([]byte, error) {
	idx := <-idle_event
	retch := aio_result_map[idx]
	defer func() { idle_event <- idx }()

	var cb *C.struct_iocb = &cbs[idx]

	var read_buf unsafe.Pointer
	C.posix_memalign(&read_buf, pagesize, C.size_t(size))
	defer C.free(read_buf)

	C.io_prep_pread(cb, C.int(fd), read_buf, C.size_t(size), C.longlong(off))
	cbs[idx].data = unsafe.Pointer(&idx)

	aio_lock.Lock()
	rt := C.io_submit(ctx, 1, &cb)
	if int(rt) < 0 {
		aio_lock.Unlock()
		return nil, errors.New("io submit failed")
	}
	aiocount++
	aio_lock.Unlock()

	select {
	case have_aio_event <- 0:
	default:
	}

	ret := <-retch

	return ret.buf, ret.err
}
开发者ID:screscent,项目名称:goaio,代码行数:32,代码来源:aio_linux.go

示例5: Put

// Put writes data associated with a key to the database.
//
// If a nil []byte is passed in as value, it will be returned by Get as an
// zero-length slice.
//
// The key and value byte slices may be reused safely. Put takes a copy of
// them before returning.
func (db *DB) Put(wo *WriteOptions, key, value []byte) error {
	var errStr *C.char
	// leveldb_put, _get, and _delete call memcpy() (by way of Memtable::Add)
	// when called, so we do not need to worry about these []byte being
	// reclaimed by GC.
	var k, v *C.char
	if len(key) != 0 {
		k = (*C.char)(unsafe.Pointer(&key[0]))
	}
	if len(value) != 0 {
		v = (*C.char)(unsafe.Pointer(&value[0]))
	}

	lenk := len(key)
	lenv := len(value)
	C.leveldb_put(
		db.Ldb, wo.Opt, k, C.size_t(lenk), v, C.size_t(lenv), &errStr)

	if errStr != nil {
		gs := C.GoString(errStr)
		C.free(unsafe.Pointer(errStr))
		return DatabaseError(gs)
	}
	return nil
}
开发者ID:olehz,项目名称:hyperleveldb-go,代码行数:32,代码来源:db.go

示例6: NewTrailDBConstructor

func NewTrailDBConstructor(path string, ofields ...string) (*TrailDBConstructor, error) {
	cons := C.tdb_cons_init()
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	var ofield_p *C.char
	ptrSize := unsafe.Sizeof(ofield_p)

	// Allocate the char** list.
	ptr := C.malloc(C.size_t(len(ofields)) * C.size_t(ptrSize))
	defer C.free(ptr)

	// Assign each byte slice to its appropriate offset.
	for i := 0; i < len(ofields); i++ {
		element := (**C.char)(unsafe.Pointer(uintptr(ptr) + uintptr(i)*ptrSize))
		cofield := C.CString(ofields[i])
		defer C.free(unsafe.Pointer(cofield))
		*element = cofield
	}

	if err := C.tdb_cons_open(cons, cpath, (**C.char)(ptr), C.uint64_t(len(ofields))); err != 0 {
		return nil, errors.New(errToString(err))
	}
	return &TrailDBConstructor{
		cons:         cons,
		path:         path,
		ofields:      ofields,
		valueLengths: make([]C.uint64_t, len(ofields)),
		valuePtr:     C.malloc(C.size_t(len(ofields)) * C.size_t(ptrSize)),
	}, nil
}
开发者ID:traildb,项目名称:traildb-go,代码行数:31,代码来源:tdb.go

示例7: fset

func fset(target, old, new uintptr) {
	pageOffset := target % pageSize
	pageAddr := target - pageOffset

	var mem []byte
	memh := (*reflect.SliceHeader)(unsafe.Pointer(&mem))
	memh.Data = pageAddr
	memh.Len = pageSize * 2
	memh.Cap = pageSize * 2

	oldAddr := make([]byte, 8)
	newAddr := make([]byte, 8)

	binary.LittleEndian.PutUint64(oldAddr, uint64(old))
	binary.LittleEndian.PutUint64(newAddr, uint64(new))

	// BSD's syscall package misses Mprotect. Use cgo instead.
	C.mprotect(unsafe.Pointer(pageAddr), C.size_t(len(mem)), protEXEC|protREAD|protWRITE)
	defer C.mprotect(unsafe.Pointer(pageAddr), C.size_t(len(mem)), protEXEC|protREAD)

	delta := make([]byte, 4)
	for i, c := range mem[pageOffset:] {
		if c == 0xe8 && int(pageOffset)+i+5 < len(mem) {
			instrAddr := pageAddr + pageOffset + uintptr(i)
			binary.LittleEndian.PutUint32(delta, uint32(old-instrAddr-5))
			if bytes.Equal(mem[int(pageOffset)+i+1:int(pageOffset)+i+5], delta) {
				binary.LittleEndian.PutUint32(mem[int(pageOffset)+i+1:], uint32(new-instrAddr-5))
				return
			}
		}
	}
	panic("cannot setup qml package for testing")
}
开发者ID:pmeido,项目名称:Arianrhod,代码行数:33,代码来源:testing.go

示例8: getUserName

func getUserName(fi os.FileInfo) (string, error) {
	var rv C.int
	var pwd C.struct_passwd
	var pwdres *C.struct_passwd
	var bufSize C.long
	var result string

	bufSize = 1024
	buf := C.malloc(C.size_t(bufSize))
	defer C.free(buf)

	uid := fi.Sys().(*syscall.Stat_t).Uid

	rv = C.mygetpwuid_r(C.int(uid), &pwd, (*C.char)(buf), C.size_t(bufSize), &pwdres)
	if rv != 0 {
		return "", errors.New("Could not read username")
	}

	if pwdres != nil {
		result = C.GoString(pwd.pw_name)
	} else {
		return "", errors.New("Could not convert username")
	}

	return result, nil
}
开发者ID:mementobackup,项目名称:client,代码行数:26,代码来源:posix.go

示例9: getGroupName

func getGroupName(fi os.FileInfo) (string, error) {
	var rv C.int
	var grp C.struct_group
	var grpres *C.struct_group
	var bufSize C.long
	var result string

	bufSize = 1024
	buf := C.malloc(C.size_t(bufSize))
	defer C.free(buf)

	gid := fi.Sys().(*syscall.Stat_t).Gid

	rv = C.mygetgrgid_r(C.int(gid), &grp, (*C.char)(buf), C.size_t(bufSize), &grpres)
	if rv != 0 {
		return "", errors.New("Could not read groupname")
	}

	if grpres != nil {
		result = C.GoString(grp.gr_name)
	} else {
		return "", errors.New("Could not convert groupname")
	}
	return result, nil
}
开发者ID:mementobackup,项目名称:client,代码行数:25,代码来源:posix.go

示例10: EnqueueReadImage

func (cq *CommandQueue) EnqueueReadImage(i *Image, blocking bool, origin, region [3]Size, rowPitch, slicePitch Size) ([]byte, error) {
	c_blocking := C.cl_bool(C.CL_FALSE)
	if blocking {
		c_blocking = C.CL_TRUE
	}

	size := Size(0)
	if i.Property(IMAGE_DEPTH) == 0 || i.Property(IMAGE_DEPTH) == 1 { // 2D image
		if rowPitch == 0 {
			rowPitch = i.Property(IMAGE_WIDTH) * i.Property(IMAGE_ELEMENT_SIZE)
		}
		size = rowPitch * i.Property(IMAGE_HEIGHT)
	} else {
		if slicePitch == 0 {
			if rowPitch == 0 {
				rowPitch = i.Property(IMAGE_WIDTH) * i.Property(IMAGE_ELEMENT_SIZE)
			}
			slicePitch = rowPitch * i.Property(IMAGE_DEPTH)
		}
		size = slicePitch * i.Property(IMAGE_DEPTH)
	}
	bytes := make([]byte, size)

	if ret := C.clEnqueueReadImage(
		cq.id, i.id, c_blocking,
		(*C.size_t)(unsafe.Pointer(&origin[0])), (*C.size_t)(unsafe.Pointer(&region[0])),
		C.size_t(rowPitch), C.size_t(slicePitch), unsafe.Pointer(&bytes[0]),
		0, nil, nil); ret != C.CL_SUCCESS {
		return nil, Cl_error(ret)
	}
	return bytes, nil
}
开发者ID:pseudomind,项目名称:go-opencl,代码行数:32,代码来源:commandQueue.go

示例11: Next

// Reads packets from a packet table starting at the current index.
// herr_t H5PTget_next( hid_t table_id, size_t nrecords, void *data)
func (t *Table) Next(data interface{}) error {
	rt := reflect.TypeOf(data)
	rv := reflect.ValueOf(data)
	c_nrecords := C.size_t(0)
	c_data := unsafe.Pointer(nil)
	switch rt.Kind() {
	case reflect.Array:
		//fmt.Printf("--> array\n")
		if rv.Cap() <= 0 {
			panic(fmt.Sprintf("not enough capacity in array (cap=%d)", rv.Cap()))
		}
		c_data = unsafe.Pointer(rv.Index(0).UnsafeAddr())
		c_nrecords = C.size_t(rv.Cap())

	case reflect.Slice:
		//fmt.Printf("--> slice\n")
		if rv.Cap() <= 0 {
			panic(fmt.Sprintf("not enough capacity in slice (cap=%d)", rv.Cap()))
		}
		slice := (*reflect.SliceHeader)(unsafe.Pointer(rv.UnsafeAddr()))
		c_data = unsafe.Pointer(slice.Data)
		c_nrecords = C.size_t(rv.Cap())

	default:
		panic(fmt.Sprintf("unhandled kind (%s) need slice or array", rt.Kind()))
	}
	//fmt.Printf("--data: %v...\n", data)
	err := C.H5PTget_next(t.id, c_nrecords, c_data)
	//fmt.Printf("--data: err [%v]\n", err)
	//fmt.Printf("--data: %v... [%v]\n", data, err)
	return togo_err(err)
}
开发者ID:pombredanne,项目名称:go-hdf5,代码行数:34,代码来源:h5pt.go

示例12: EnqueueWriteBuffer

func (cq *CommandQueue) EnqueueWriteBuffer(buf *Buffer, data []byte, offset uint32) error {

	if ret := C.clEnqueueWriteBuffer(cq.id, buf.id, C.CL_TRUE, C.size_t(offset), C.size_t(len(data)), unsafe.Pointer(&data[0]), 0, nil, nil); ret != C.CL_SUCCESS {
		return Cl_error(ret)
	}
	return nil
}
开发者ID:pseudomind,项目名称:go-opencl,代码行数:7,代码来源:commandQueue.go

示例13: EnqueueReadBuffer

func (cq *CommandQueue) EnqueueReadBuffer(buf *Buffer, offset uint32, size uint32) ([]byte, error) {
	bytes := make([]byte, size)
	if ret := C.clEnqueueReadBuffer(cq.id, buf.id, C.CL_TRUE, C.size_t(offset), C.size_t(size), unsafe.Pointer(&bytes[0]), 0, nil, nil); ret != C.CL_SUCCESS {
		return nil, Cl_error(ret)
	}
	return bytes, nil
}
开发者ID:pseudomind,项目名称:go-opencl,代码行数:7,代码来源:commandQueue.go

示例14: SetSize

func (self *Canvas) SetSize(width, height uint) error {
	if C.MagickSetSize(self.wand, C.size_t(width), C.size_t(height)) == C.MagickFalse {
		return fmt.Errorf("Could not set size: %s", self.Error())
	}

	return nil
}
开发者ID:phacops,项目名称:canvas,代码行数:7,代码来源:canvas.go

示例15: InitiatorTransceiveBits

// Transceive raw bit-frame to a target. n contains the received byte count on
// success, or is meaningless on error. The current implementation will return
// the libnfc error code in case of error, but this is subject to change. If
// txLength is longer than the supplied slice, an error will occur. txPar has to
// have the same length as tx, dito for rxPar and rx. An error will occur if any
// of these invariants do not hold.
//
// tx contains a byte slice of the frame that needs to be transmitted. txLength
// contains its length in bits.
//
// For example the REQA (0x26) command (the first anti-collision command of
// ISO14443-A) must be precise 7 bits long. This is not possible using
// Device.InitiatorTransceiveBytes(). With that function you can only
// communicate frames that consist of full bytes. When you send a full byte (8
// bits + 1 parity) with the value of REQA (0x26), a tag will simply not
// respond.
//
// txPar contains a byte slice of the corresponding parity bits needed to send
// per byte.
//
// For example if you send the SELECT_ALL (0x93, 0x20) = [ 10010011, 00100000 ]
// command, you have to supply the following parity bytes (0x01, 0x00) to define
// the correct odd parity bits. This is only an example to explain how it works,
// if you just are sending two bytes with ISO14443-A compliant parity bits you
// better can use the Device.InitiatorTransceiveBytes() method.
//
// rx will contain the response from the target. This function will return
// EOVFLOW if more bytes are received than the length of rx. rxPar contains a
// byte slice of the corresponding parity bits.
//
// The NFC device (configured as initiator) will transmit low-level messages
// where only the modulation is handled by the PN53x chip. Construction of the
// frame (data, CRC and parity) is completely done by libnfc.  This can be very
// useful for testing purposes. Some protocols (e.g. MIFARE Classic) require to
// violate the ISO14443-A standard by sending incorrect parity and CRC bytes.
// Using this feature you are able to simulate these frames.
func (d Device) InitiatorTransceiveBits(tx, txPar []byte, txLength uint, rx, rxPar []byte) (n int, err error) {
	if *d.d == nil {
		return ESOFT, errors.New("device closed")
	}

	if len(tx) != len(txPar) || len(rx) != len(rxPar) {
		return ESOFT, errors.New("Invariant doesn't hold")
	}

	if uint(len(tx))*8 < txLength {
		return ESOFT, errors.New("Slice shorter than specified bit count")
	}

	txptr := (*C.uint8_t)(&tx[0])
	txparptr := (*C.uint8_t)(&txPar[0])
	rxptr := (*C.uint8_t)(&rx[0])
	rxparptr := (*C.uint8_t)(&rxPar[0])

	n = int(C.nfc_initiator_transceive_bits(
		*d.d,
		txptr, C.size_t(txLength), txparptr,
		rxptr, C.size_t(len(rx)), rxparptr,
	))

	if n < 0 {
		err = Error(n)
	}

	return
}
开发者ID:harikb,项目名称:nfc,代码行数:66,代码来源:initiator.go


注:本文中的C.size_t函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。