《高性能的ASN.1编译器 毕业论文翻译内容》由会员分享,可在线阅读,更多相关《高性能的ASN.1编译器 毕业论文翻译内容(13页珍藏版)》请在金锄头文库上搜索。
1、附录附录A High-performance ASN.1 compilerMichael Sample and Gerald NeufeldError managementError management is important, but it must be implemented without incurring too much cost for the common case where there are no errors. One method of streamlining error management is to eliminate it by assuming th
2、at the decoded values are always correct. This is not acceptable for a reliable implementation.To implement a complete yet light-weight error management scheme for the decoders, we used the setjmp and longjmp functions 23. Previously, the availability of these functions was very system dependent; ho
3、wever, they are now part of the ANSI Standard C Library. Before decoding begins, set jmp is called to record the current environment (processor registers,etc.). The environment value set by setjmp is then passed into the decoding routine. Every decoding routine takes this parameter. When the decodin
4、g routines encounter a serious error such as running out of memory for the decoded value, they call longjmp with the environment value they were given as a parameter, along with a unique error code. This returns execution directly to where setjmp was called along with the error code.The setjmp and l
5、ongjmp based error management is simple and does not impact on the performance of decoding correctly encoded values (other than an extra parameter to each decoding routine). Other error management techniques, such as passing back error codes, that the calling functions must check will affect the dec
6、oding performance even for correctly encoded values.Buffer managementEncoding and decoding performance is greatly affected by the cost of writing to and reading from buffers. Thus, efficient buffer management is necessary. Flexibility is also important to allow integration of the generated encoders
7、and decoders into existing environments. To provide both of these features, the calls to the buffer routines are actually macros that can be configured as desired. They must be configured prior to compiling the encode/decode library and the generated code. Since virtually all buffer calls are made f
8、rom the encode/decode library routines, bufler routine macros should not bloat code size significantly. If a single, simple buffer type can be used in the target environment, the buffer routine macros can be defined to call the macros for the simple buffer type. This results in the buffer type being
9、 bound at the time the generated code is compiled, with no function call overhead from the encode or decode routines. However, this also means that the encode and decode library will only work with that buffer type.If multiple buffer formats must be supported at runtime, the buffer macros can be def
10、ined like the ISODE buffer calls, where a buffer type contains pointers to the buffer routines and data of user defined buffer type. This approach will hurt performance since each buffer operation will be an indirect function call. The backwards encoding technique used by snacc requires special buff
11、er primitives that write from the end of the buffer towards the front. The decoder routines require forward buffer reading routines.Memory managementLike buffer management, memory management is very important for efficient decoders. Snacc decoders allocate memory to hold the decoded value. After the
12、 decoded value has been processed it is usually freed. The decoding and freeing routines in the library and the ones generated by snacc both use the memory manager. The decoders allocate memory with the AsnlAlloc routine and the freeing routines call AsnlFree.The configuration header file allows the
13、 user to change the default memory manager prior to compiling the library and the generated code. Snacc provides a particularly efficient memory manager, discussed shortly, called nibble memory.The memory manager must provide three routines: AsnlAlloc, Asnlfr ee and CheckAsnlAlloc. These memory rout
14、ines should have the following interfaces:void * AsnlAlloc(unsigned longint size);void AnslFree(void * ptr);int CheckAsnlAlloc(void * ptr, ENV TYPE env);The decoders assume that AsnlAlloc returns a zeroed block of memory. This saves explicit initialization of OPTIONAL elements with NULL in the gener
15、ated decoders. The ENV TYPE parameter is used with the error management system for calls to longjmp.To change the memory management system the configuration file needs to be edited. For example, ifperformance is not an issue and you want to use calloc and free, the configuration file would be as fol
16、lows:#include malloc.h#define AsnlAlloc(size) calloc(l, size)#define AsnlFree(ptr) free (ptr)#define CheckAsnlAlloc(ptr, env)if (ptr)-NULL)longjmp(env,-27);The nibble memory system does not need explicit flees of each component so the generated free routines are not needed. However, if you change the memory management to use something like malloc and free you should use the generated free routines. By default, snacc uses a nibble m