Copy between arrays with different element size in C -
i need copy elements uint8_t array float array.
i wrote simple function came mind instantly.
float *uint8_t_mas_to_float_mas(uint8_t *src, int size) { float *dst = null; if (!src) return null; dst = (float*)calloc(size, sizeof(float)); if (!dst) return null; (int = 0; < size; i++) dst[i] = (float)src[i]; return dst; }
but think it's not effective , unfortunatelly cant come else.
can help?
thank you.
you should write (equivalent):
float *uint8_t_mas_to_float_mas(uint8_t *src, int size) { if (!src) return null; float *dst = (float*)malloc(size*sizeof(float)); if (!dst) return null; (int = 0; < size; i++) dst[i] = (float)src[i]; return dst; }
this ok. let optimizer it's job. bottleneck malloc
call - don't need here, unless copying millions of elements.
Comments
Post a Comment