D 2016-09-24T15:53:21.043 L byteArray\sObject\sType P bcef79d4d04159ecfbf03d7457f263a592543f4e U dkf W 2024
typedef struct ByteArray {
int used; /* The number of bytes used in the byte
* array. */
int allocated; /* The amount of space actually allocated
* minus 1 byte. */
unsigned char bytes[]; /* The array of bytes. The actual size of this
* field depends on the 'allocated' field
* above. */
} ByteArray;
The buffer is allocated contiguously with this structure, and is managed with the usual buffer growth strategy when appends are being done. However, it's also reasonably common for buffers to be shrunk. Because buffers can be reallocated, it is important for pointers to ByteArrays to be not kept by code other than the tclBinary.c core. It's also important to not assume that the pointer returned by Tcl_GetByteArrayFromObj or Tcl_SetByteArrayLength will never be switched out from under your feet.
On the other hand, it's a common pattern to get a buffer of the right size from an unshared bytearray object and to write into it to make the contents right. This is a supported usage pattern.
Z 5bb032132ef1fac4ae57ebf7700cd5a9