Chinaunix首页 | 论坛 | 博客
  • 博客访问: 354564
  • 博文数量: 90
  • 博客积分: 847
  • 博客等级: 准尉
  • 技术积分: 1373
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-02 10:54
个人简介

跌打滚爬中的小菜鸟...

文章分类

全部博文(90)

文章存档

2015年(5)

2013年(47)

2012年(38)

我的朋友

分类: 其他UNIX

2013-09-19 22:24:47

在RPGLE和CLLE中都有basing pointer和based variable的概念.
basing pointer本质是个pointer, 只是这个pointer被用在based variable中用来指定 起始内存位置.
based variable本质是个普通变量, 可能是char类型, 也可能是日期,时间等类型, 只不过这个普通变量的内存不是系统自动分配的, 而是依赖于一个指针(该指针被称为basing pointer), 并且这个变量在内存中的位置是可变的(随着pointer指向位置的不同而变化)


Basing pointers are used to locate the storage for based variables. The storage is

accessed by defining a field, array, or data structure as based on a particular basing
pointer variable and setting the basing pointer variable to point to the required
storage location.
For example, consider the based variable MY_FIELD, a character field of length 5,
which is based on the pointer PTR1. The based variable does not have a fixed
location in storage. You must use a pointer to indicate the current location of the
storage for the variable.
Suppose that the following is the layout of some area of storage:
If we set pointer PTR1 to point to the G,
-------------------------------------------------------------
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
-------------------------------------------------------------


   PTR1-------------------.
                          |
                          V
-------------------------------------------------------------
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
-------------------------------------------------------------

MY_FIELD is now located in storage starting at the ’G’, so its value is ’GHIJK’. If
the pointer is moved to point to the ’J’, the value of MY_FIELD becomes ’JKLMN’:
If MY_FIELD is now changed by an EVAL statement to ’HELLO’, the storage
               PTR1-------------------.
                                      |
                                      V
-------------------------------------------------------------
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
-------------------------------------------------------------
starting at the ’J’ would change:
               PTR1-------------------.
                                      |
                                      V
-------------------------------------------------------------
| A | B | C | D | E | F | G | H | I | H | E | L | L | O | O |
-------------------------------------------------------------
Use the BASED keyword on the definition specification (see
“BASED(basing_pointer_name)” on page 325) to define a basing pointer for a field.
Basing pointers have the same scope as the based field.
The length of the basing pointer field must be 16 bytes long and must be aligned
on a 16 byte boundary. This requirement for boundary alignment can cause a
pointer subfield of a data structure not to follow the preceding field directly, and
can cause multiple occurrence data structures to have non-contiguous occurrences.
For more information on the alignment of subfields, see “Aligning Data Structure
Subfields” on page 140.
阅读(1644) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~