[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]
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*/);
(*1) :
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!
'Language > C&C++' 카테고리의 다른 글
[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++] 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 |