高性能的ASN.1编译器 毕业论文翻译内容.doc
《高性能的ASN.1编译器 毕业论文翻译内容.doc》由会员分享,可在线阅读,更多相关《高性能的ASN.1编译器 毕业论文翻译内容.doc(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 that
2、 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; howe
3、ver, 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 decoding
4、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 lon
5、gjmp 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 decod
6、ing 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 an
7、d 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 fro
8、m 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 b
9、ound 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 defin
10、ed 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 buffer
11、 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 d
12、ecoded 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 u
13、ser 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 routin
14、es 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 generat
15、ed 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 follo
16、ws:#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
17、memory management to use something like malloc and free you should use the generated free routines. By default, snacc uses a nibble memory scheme to provide efficient memory management. Nibble memory works by getting a large block of memory from the O/S for allocating smaller requests. When the deco
18、ded PDU is no longer required by the application the entire space allocated to the PDU can be freed by calling a routine that simply resets a pointer. There is no need to use the snacc generated free routines to traverse the entire data structure, freeing a piece at a time.If calloc and free are use
19、d for memory management instead of nibble memory, the generated free routines must be used to free the values. The generated free routines hierarchically free all of a PDUs memory using a depth first algorithm.C+ designThe C+ backend of snacc was designed after the C backend had been written. The ba
20、sic model that the generated C+ uses is similar to that of the generated C, but benefits from the object oriented features of C+.Some cleaner designs were rejected either due to their poor performance or the inability of the available C+ compiler to handle certain language features. Tags and lengths
21、 would fit nicely into their own classes, but performance was considerably worse than the technique used in the C model. The C design was retained in the C+ model for this reason. For error management, C+s try and catch 22 are obvious replacements for the setjmp and longjmp used by the C decoders. U
22、nfortunately, this is a newer C+ feature and was not yet supported. C+ templates are very attractive for type safe lists (for SET OF and SEQUENCE OF) without duplicating code. Since template support was weak in the available C+ compiler, templates were rejected. Instead, each SET OF and SEQUENCE OF
23、type generates its own new class with all of the standard list routines.Every ASN. 1 type is represented by a C+ class with the following characteristics:1. Inherits from the AsnType base class.2. Has a parameterless constructor.3. Has a clone method, Clone.4. Has a PDU encode and decode method, BEn
24、c and BDec.5. Has a content encode and decode method, BEnc- Content and BDecContent.6. Has top level interfaces to the PDU encode and decode methods (handles the setjmp, etc.) for the user, BEncPdu and BDecPdu.7. Has print method, pr int.The foliowing C+ fragment shows the class features listed abov
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 高性能的ASN.1编译器 毕业论文翻译内容 性能 ASN 编译器 毕业论文 翻译 内容
链接地址:https://www.31ppt.com/p-3995371.html