EETimes

Embedded Systems December 2000 Vol13_13

Issue link: http://dc.ee.ubm-us.com/i/71850

Contents of this Issue

Navigation

Page 156 of 197

altogether wi ll be needed. The vaL- LocO wi ll ensu re that allocation starts on a page boundary. Data initialization-done only if the last a rgument pointer to initialize element i non-NULL, and identical for bOLh daaO and daavO-is done ju L befol"e pointer setup. The initial- ization element is copied repeatedly to fill the data area. T chose not to use a memmoveO or any other standard copy routine because I wanted to remain as independent of any library require- ments as possible. The pointer area setup is the last and most complex step. This is done by ptr _initO and two other recursive routines it calls-off 0 and doffO. The ptr _i ni t 0 routine repeatedly calls itself with each new invocation descending to a lower level in the pointer array hierarchy. The fir t al"gu- ment, LeveL, is incremented by 1 for each successive array dimension. For a three-dimensional array, the level would go from 0 to 2. The dim_ind[] (dimension index) array tells each recursive invocation of ptr _i nit 0 exactly where with in each level the pointers returned from the next level are to be stored. The dim_ind[] array will have, in some recursive call (except tile last), every combination of array values. The last level is special because its pointers point to data and not to othe r poin ters. dim_ind[] wi ll be zeroed. Successive calls to ptr_initO will increment each d imensional level by one from zero to the maximum subsc ript. Thus, a three-dimensional array dimen- sioned 5 x 10 x 15 will see dim_ind[Q] go from 0 to 4, dim_ind[1] go from 0 to 9, and dim_i nd[2] stay O. Every pointer is calculated from three parts: the constant base pointer; the off- set of tile arrays of pointers for a given level, calculated by off(); and tile data Initially offset of the arrays of pointers within each level, calculated by doffO. Again, the last level is dilferent because it's the data element level, which has a different basic data unit element size, and because no further levels are called. To accom- modate non-zero starting subscripts, a few adjustments to the pointers are made. Each recursive call to ptr_initO has its return value adjusted by an amount based on that level's desired starting subscript obtained from the st[] array. The passed-back pointer for one dimensional arrays, which do not need a pointer sU"l.ICture, is adjusted separately. The LeveL and dim_ind[] argu- ments are the only o nes modified recursively. The others are al l statically set up before ptr_initO is called and remain unchanged. In my original version of this code, these were al l file global statics. I eliminated them in favo r of passed arguments in order to

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems December 2000 Vol13_13