discountsgasil.blogg.se

Vector code c
Vector code c







  1. #Vector code c how to#
  2. #Vector code c code#

Recommend to use the same one prefix with all external types, names and functions.

#Vector code c code#

Is the code clear, what can I do to make it easier to follow? I'd expect the same with delete_void_vector(NULL, foo). I'd detect overflow in size computations.įree(NULL) is well defined. Add code to handle doubling array size when size is 0.Ĭreate a VV_DEFAULT_SIZE 16u if desired for the user to call with new_void_vector(VV_DEFAULT_SIZE). Suggest setting aside size = 0 as something special and allow an initial vector size of 0. I see no real value in a default size of 16. It seems odd to have 2 forms of error signaling: error codes and NULL. I'd re-work calls to return an error code on vv_pop(), like vv_err vv_pop(void_vector **vv, void **el). If NULL is not to be allowed (which I think is a bad idea) as a storable void *, vv_push(&vv, NULL) should error. Vv_pop(), vv_read_index() return NULL as an error indicator and can return NULL as a valid return. Void* vv_read_index(void_vector *vv, size_t index) const void* vv_read_index(void_vector *vv, size_t index) The stored ellement is a void *, changing the return type to const is not good.

#Vector code c how to#

I'd expect at least some commentary about the roll of the functions and how to use them near the function declaration section.Īssume a user will read the header and not delve into implementation. I am trying to minimize use of external libraries (although I don't think it would be possible to avoid stdlib.h). =7009= ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) =7009= For counts of detected and suppressed errors, rerun with: -v =7009= All heap blocks were freed - no leaks are possible =7009= total heap usage: 14 allocs, 14 frees, 1,616 bytes allocated =7009= in use at exit: 0 bytes in 0 blocks I ran this through valgrind and got the following output: =7009= HEAP SUMMARY:

  • I'm not overly concerned about the contents of void_vector_tb.c.
  • Is there an obvious way to greatly improve the efficiency?.
  • Is the code clear, what can I do to make it easier to follow?.
  • I would greatly appreciate your time and any comments but I'm particularly interested in the following points: Compilation is performed by gcc -ggdb void_vector_tb.c -o void_vector_tb I am using this as test bench - void_vector_tb.c #include Vv_read_index(void_vector *vv, size_t index)ĭelete_void_vector(void_vector *vv, void (del_el)(void*)) Void_vector *new_vv = realloc((*vv), sizeof(void_vector) Void_vector* vv = malloc(sizeof(void_vector) + sizeof(void*) * size) Void delete_void_vector(void_vector *vv, void (del_el)(void*)) Vv_err vv_push(void_vector **vv, void *el) Ĭonst void* vv_read_index(void_vector *vv, size_t index)

    vector code c

    Void_vector* new_void_vector(size_t size) I have implemented a simple dynamic vector library in C.









    Vector code c