We stand with Ukraine
Yes, it does allocate more memory than the size of the data. If you do not pre-allocate the output buffer then at minimum it allocates a block a little less than 4K and writes the encoded data into it. If the total amount of encoded data is less than or equal to the size of the block, it allocates the required number of bytes to store the encoded data, copies the encoded data to the new block, frees the original 4K block, and returns the new block. If the amount of encoded data is too large to fit into a single block it allocates as many blocks as necessary, and just before returning to the caller it allocates a final block that is large enough to hold all the encoded data, copies all the encoded data from the other blocks into it, frees the other blocks, and returns the final block to the caller.
If you pre-allocate the output buffer then at minimum it allocates about 80 bytes as working storage. No blocks are allocated as described above for the output memory. All encoded data is written directly to the pre-allocated output buffer, which must be large enough to hold the entire encoded message, or else a code of MORE_BUF(1) is returned.
Regardless of which way you allocate, the encoder allocates working storage as needed. The amount of working storage varies depending on factors such as whether the DEBUGPDU flag was set, what the encoding rules are, and what the ASN.1 type of the values to be encoded are.
Therefore, if you pre-allocate memory at least 84 bytes will be allocated, and if you don't pre-allocate memory at least 4148 bytes will be allocated.
The samples included with some of the Knowledge Center answers are meant for your general understanding of the OSS products. Different versions of the products might produce slightly different outputs. Consult the products documentation and samples for the most up-to-date products information and code examples.
Test drive the OSS Nokalva ASN.1, LTE, and XML Tools now! Your trial includes complete software, documentation, sample programs, free 24x7 technical support and more.
Our expert personnel can help you learn ASN.1!
We offer 4-day ASN.1 courses at our headquarters or your premises.