Archived Forum Post

Index of archived forum posts

Question:

Redundant functions in the CkByteData API

Nov 04 '15 at 03:40

Looking through the CkByteData API documentation, I've noticed what might seem like some redundant functionality:

const unsigned char *CkByteData_getBytes(HCkByteData cHandle);

Returns a pointer to the bytes contained within the object. Be very careful with the pointer that is returned. If more data is appended to the object, an internal reallocation may occur such that the previously returned pointer is no longer valid.

const unsigned char *CkByteData_getData(HCkByteData cHandle);

Returns a pointer to the internal buffer. Be careful with this method because if additional data is appended, the data within the object may be relocated and the pointer may cease to be valid.


BOOL CkByteData_preAllocate(HCkByteData cHandle, unsigned long expectedNumBytes);

This method can be called to help optimize internal memory re-allocation. If, for example, many calls will be made to append data, and the total size is approximately known, then this method can be called to pre-allocate the internal buffer to the expected total size.

void CkByteData_ensureBuffer(HCkByteData cHandle, unsigned long expectedNumBytes);

This method can be called to help optimize internal memory re-allocation. If, for example, many calls will be made to append data, and the total size is approximately known, then this method can be called to pre-allocate the internal buffer to the expected total size.

Are there any differences between these pairs of functions?

Also, is there a way to copy one HCkByteData object to another?


Answer

There's no difference between the functions. I'll mark one of each as deprecated..