📄 bytearrobj.3
字号:
'\"'\" Copyright (c) 1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: ByteArrObj.3,v 1.3 2001/04/04 16:07:20 kennykb Exp $'\" .so man.macros.TH Tcl_ByteArrayObj 3 8.1 Tcl "Tcl Library Procedures".BS.SH NAMETcl_NewByteArrayObj, Tcl_SetByteArrayObj, Tcl_GetByteArrayFromObj, Tcl_SetByteArrayLength \- manipulate Tcl objects as a arrays of bytes .SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spTcl_Obj *\fBTcl_NewByteArrayObj\fR(\fIbytes, length\fR).spvoid \fBTcl_SetByteArrayObj\fR(\fIobjPtr, bytes, length\fR).spunsigned char *\fBTcl_GetByteArrayFromObj\fR(\fIobjPtr, lengthPtr\fR).spunsigned char *\fBTcl_SetByteArrayLength\fR(\fIobjPtr, length\fR).SH ARGUMENTS.AS "unsigned char" *lengthPtr in/out.AP "CONST unsigned char" *bytes inThe array of bytes used to initialize or set a byte-array object..AP int length inThe length of the array of bytes. It must be >= 0..AP Tcl_Obj *objPtr in/outFor \fBTcl_SetByteArrayObj\fR, this points to the object to be converted tobyte-array type. For \fBTcl_GetByteArrayFromObj\fR and\fBTcl_SetByteArrayLength\fR, this points to the object from which to getthe byte-array value; if \fIobjPtr\fR does not already point to a byte-arrayobject, it will be converted to one..AP int *lengthPtr outIf non-NULL, filled with the length of the array of bytes in the object..BE.SH DESCRIPTION.PPThese procedures are used to create, modify, and read Tcl byte-array objectsfrom C code. Byte-array objects are typically used to hold theresults of binary IO operations or data structures created with the\fBbinary\fR command. In Tcl, an array of bytes is not equivalent to astring. Conceptually, a string is an array of Unicode characters, while abyte-array is an array of 8-bit quantities with no implicit meaning.Accesser functions are provided to get the string representation of abyte-array or to convert an arbitrary object to a byte-array. Obtaining thestring representation of a byte-array object (by calling\fBTcl_GetStringFromObj\fR) produces a properly formed UTF-8 sequence with aone-to-one mapping between the bytes in the internal representation and theUTF-8 characters in the string representation. .PP\fBTcl_NewByteArrayObj\fR and \fBTcl_SetByteArrayObj\fR willcreate a new object of byte-array type or modify an existing object to have abyte-array type. Both of these procedures set the object's type to bebyte-array and set the object's internal representation to a copy of thearray of bytes given by \fIbytes\fR. \fBTcl_NewByteArrayObj\fR returns apointer to a newly allocated object with a reference count of zero.\fBTcl_SetByteArrayObj\fR invalidates any old string representation and, ifthe object is not already a byte-array object, frees any old internalrepresentation..PP\fBTcl_GetByteArrayFromObj\fR converts a Tcl object to byte-array type andreturns a pointer to the object's new internal representation as an array ofbytes. The length of this array is stored in \fIlengthPtr\fR if\fIlengthPtr\fR is non-NULL. The storage for the array of bytes is owned bythe object and should not be freed. The contents of the array may bemodified by the caller only if the object is not shared and the callerinvalidates the string representation. .PP\fBTcl_SetByteArrayLength\fR converts the Tcl object to byte-array typeand changes the length of the object's internal representation as anarray of bytes. If \fIlength\fR is greater than the space currentlyallocated for the array, the array is reallocated to the new length; thenewly allocated bytes at the end of the array have arbitrary values. If\fIlength\fR is less than the space currently allocated for the array,the length of array is reduced to the new length. The return value is apointer to the object's new array of bytes. .SH "SEE ALSO"Tcl_GetStringFromObj, Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount.SH KEYWORDSobject, byte array, utf, unicode, internationalization
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -