Assume I have some C++ method which returns back a pointer to an object. Something in the header file that looks like this:
uint8_t* getData(void);
This guy returns a byte array, but there is nothing that says if this is a dynamic or statically generated piece of data (local to the class or created with new).
Is there a specific naming convention in C++ to distinguish between methods that return memory that is dynamically allocated (and so must be deleted by the requester), vs methods that just return a reference to a statically define piece of data?
What is the preferred way to do this, or does it depend on the situation?
My conventions are:
is statically allocated, or at least it’s not my responsibility for deleting this data. However if it’s an array I would write:
Or define a container for that.
allocates single object and I own it from now on.
allocates single object with shared ownership.
allocates an array, vector owns the memory.