Hello I have started writing common data structure library in C similar to STL. Here is the link . http://code.google.com/p/cstl/
I struggled a lot of whether to 开发者_如何学运维go ahead with having void*
as basic element for data structure. and End up with structure which has two elements
typedef struct __c_lib__object {
void* raw_data;
size_t size;
} clib_object, *clib_object_ptr;
This approach allow me to store each element, but it requires lot of memory allocation , during saving and returning back the element from the container.
Can anybody please review this , and let me know if there is any other approach.
Thanks Avinash
Names starting with double-underscore are reserved to 'the implementation' and should be avoided in user code.
Personally, I dislike typedefs for pointers; I'd rather use clib_object *x;
than clib_object_ptr x;
.
Why do you need to record the size of the object?
精彩评论