esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems
https://www.thanassis.space/asn1.html
Other
272 stars 58 forks source link

Reduce the memory footprint of autogenerated C structures to the bare minimum #247

Closed ThibFrgsGmz closed 2 years ago

ThibFrgsGmz commented 2 years ago

Discussed in https://github.com/ttsiodras/asn1scc/discussions/246

Originally posted by **ThibFrgsGmz** September 23, 2022 Hi, Please correct me if I have misunderstood the way to use `ASN.1`. To serialize a message according to a `uPER`/`ACN` encoding protocol, you have to - define a `C structure` of the message, - fill it with good values, - pass it to the encoding function to have a serialized message in the `BitStream` object. This `C structure` of the message would be allocated at compile time in the `BSS` section (or on the `stack` like your unit tests but there is a big risk of stack overflow). So I'm interested in the memory footprint of the structure and what I see worries me. I see that my `U8`/`I8`/`U16`/`I16` types are in fact `asn1SccUint`/`asn1SccSint` which are `64 bits` or `32 bits` depending on whether `WORD_SIZE` is `8`. Note: same story for `F32` floats. Could you tell me the reason why the members of `C structures` are `32/64 bits`? Isn't there a way to reduce their memory footprint? I mean, a `U8` is an `unsigned char`, a `U16` an `unsigned short`, etc.
maxime-esa commented 2 years ago

Fixed in release 4.3.1.3: https://github.com/ttsiodras/asn1scc/releases/tag/4.3.1.3