Language/C&C++ 2008.01.06 23:17
There are two different API implementation to get data.
// (*1) return, length of data remained.
get_data(char* buffer /*in/out*/, int buffer_size/*in*/);
// (*2) caller should free memory of (*data).
get_data(char** data/*out*/, int* len/*out*/);
This is very clear and safe, but inefficient in performance point of view and difficult to implement.
And, the one who allocates memory, frees it too. (very reasonable. So, there is less risk of memory leak.)
(*2) : contrary to (*1)
Which one is better? In general, (*1) is recommended.
In terms of memory allocation/free, if possible, the one who allocates should free it. In case of this is not reasonable, at least, allocation-free-pair should be easy to track!
|[C/C++] Abusing throwing exception drops performance severely. (0)||2008.04.10|
|[C/C++] Attention! Integer-operation to avoid float-operation... (0)||2008.03.21|
|[C/C++] API to getting bufferred data... (0)||2008.01.06|
|[C/C++] Use instantiate-function(factory function) to hide concreate class... (0)||2007.12.13|
|[C/C++] Case study! Bad example about ignoring data-align.. (0)||2007.07.09|
|[C/C++] Case study! Bad example about endianness. (0)||2007.06.29|