在重构Handler时遇到bit field初始化问题

本文探讨了在使用C++11进行嵌入式开发时如何处理内存限制的问题,特别是在Handler类中利用bitfields来节省内存。由于C++11不支持bitfields特性,文章进一步说明了这一限制,并指出C++20开始支持该特性。

由于要支持嵌入式产品,CoreLooper只能坚守c++ 11

为了节省内存,Handler中有些成员变量采用bit field,但c++ 11不支持 bit field 

只有c++20才支持如下用法

class Handler

{

 int x1 : 8 = 42;
 int x2 : 8 { 42 };   
};

详见

https://en.cppreference.com/w/cpp/language/bit_field



结构体如下 struct request_st { request_state_t state; /*(modules should not modify request state)*/ int http_status; union { struct { uint32_t state; /*(modules should not modify request state)*/ uint32_t id; int32_t rwin; int32_t swin; int16_t rwin_fudge; uint8_t prio; } h2; struct { off_t bytes_written_ckpt; /*used by http_request_stats_bytes_out()*/ off_t bytes_read_ckpt; /*used by http_request_stats_bytes_in() */ off_t te_chunked; } h1; } x; http_method_t http_method; http_version_t http_version; const plugin *handler_module; void **plugin_ctx; /* plugin connection specific config */ connection *con; /* config conditions (internal) */ uint32_t conditional_is_valid; struct cond_cache_t *cond_cache; struct cond_match_t **cond_match; struct cond_match_t *cond_match_data; request_config conf; /* request */ uint32_t rqst_header_len; uint64_t rqst_htags;/* bitfield of flagged headers present in request */ array rqst_headers; request_uri uri; physical physical; array env; /* used to pass lighttpd internal stuff */ off_t reqbody_length; /* request Content-Length */ off_t resp_body_scratchpad; buffer *http_host; /* copy of array value buffer ptr; not alloc'ed */ const buffer *server_name; buffer target; buffer target_orig; buffer pathinfo; buffer server_name_buf; void *dst_addr; buffer *dst_addr_buf; /* response */ uint32_t resp_header_len; uint64_t resp_htags; /*bitfield of flagged headers present in response*/ array resp_headers; char resp_body_finished; char resp_body_started; char resp_send_chunked; char resp_decode_chunked; char resp_header_repeated; char loops_per_request; /* catch endless loops in a single request */ int8_t keep_alive; /* only request.c can enable it, all other just disable */ char async_callback; buffer *tmp_buf; /* shared; same as srv->tmp_buf */ response_dechunk *gw_dechunk; unix_timespec64_t start_hp; int error_handler_saved_status; /* error-handler */ http_method_t error_handler_saved_method; /* error-handler */ struct chunkqueue write_queue; /* HTTP response queue [ file, mem ] */ struct chunkqueue read_queue; /* HTTP request queue [ mem ] */ struct chunkqueue reqbody_queue; /*(might use tempfiles)*/ struct stat_cache_entry *tmp_sce; /*(value valid only in sequential code)*/ int cond_captures; int h2_connect_ext; };
最新发布
10-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值