Generic static Vector data type in C with data segment memory

Is it possible to create a generic Vector like data structure in C, with out using heap. Basically I need a array data type but a more generalized version on if it. typedef struct { /* some data types*/ }TYPE1; typedef struct { /* some data types*/ }TYPE2; typedef struct _GCACHE_T { const int element_size; const int count; struct _ELEMENT { UBYTE data[element_size]; BOOLEAN is_valid; }element[count]; }GCACHE_T; GCACHE_T f_cache1 = {sizeof(TYPE1), 15, {0} }; GCACHE_T f_cache2 = {sizeof(TYPE2), 10, {0} }; The above code will not compile but I have provided it for a better clarity on my requirement. This would have been easy implemted provided heap memory was allowed to use. Since the code is meant for small micros heap memory usage is not allowed. I could have used right away, but just checking if it can be done in a generic way. TYPE1 f_cache1[15]; TYPE2 f_cache2[10]; The Vector will not grow in size. I could have also used a union but there is a memory trade off so not willing to use it.
What is the cost in memory if you use a union?

以上就是Generic static Vector data type in C with data segment memory的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏