CFDataCreateWithBytesNoCopy

Header: CFData.h Carbon status: Supported

Creates an immutable CFData object from an external (client-owned) byte buffer.

CFDataRef CFDataCreateWithBytesNoCopy (
    CFAllocatorRef allocator, 
    const UInt8 *bytes, 
    CFIndex length, 
    CFAllocatorRef bytesDeallocator
);
Parameter descriptions
allocator

Pass a reference to an allocator object or pass NULL to request the current default allocator.

bytes

Pass a pointer to a byte buffer that may be used as the backing store of the CFData object.

length

Pass an integer specifying the number of bytes in the buffer.

bytesDeallocator

Pass a reference to an allocator object to be used to deallocate the external buffer when the CFData object is deallocated. If the default allocator is suitable for this purpose, pass NULL. If you do not want the created CFData object to deallocate the buffer (that is, you assume responsibility for freeing it yourself), pass kCFAllocatorNull.

function result

A reference to an immutable CFData object or NULL if there was a problem creating the object.

DISCUSSION

The CFDataCreateWithBytesNoCopy function creates an immutable CFData object from a buffer of unstructured bytes. Unless the situation warrants otherwise, the created object does not copy the external buffer to internal storage but instead uses the buffer as its backing store. However, you should never count on the object using the external buffer since it could copy the buffer to internal storage or might even dump the buffer altogether and use alternative means for storing the bytes.

The function includes a bytesDeallocator parameter with which to specify an allocator to use for deallocating the external buffer when the CFData object is deallocated. If you want to assume responsibility for deallocating this memory, specify kCFAllocatorNull for this parameter. If at creation time the CFData object decides it can't use the buffer, and bytesDeallocator holds a reference to a valid allocator object, it will use this object to free the buffer at that time.

AVAILABILITY

Supported in Carbon. Available in Carbon 1.0.2 and later.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)