0

可变长度表中的内存分配中, NealB 提到了在非 CICS COBOL 程序中分配/取消分配内存的 LE 例程。

我非常想知道这是如何完成的:如何调用 LE 例程。(我熟悉 LINKAGE SECTION 和 SET ADDRESS。)

由于我目前无法访问 IBM 大型机——这意味着无法访问在线文档——一些代码片段可以启发我。

4

2 回答 2

2

在 LE 环境中,您将调用 CEEGST 和 CEEFRST 来获取和释放存储空间。

它们都将 12 字节的结果标记作为第一个参数——如果你传递 null,LE 将在失败时为你异常终止。

第二个参数是地址。

在 CEEGTST 的情况下,您还传递了第三个长度参数。

分配示例:

Call 'CEEGTST' using
  omitted
  address of some-linkage-item
  length of some-linkage-item
End-Call

免费示例:

Call 'CEEFRST' using
  omitted
  address of some-linkage-item
End-Call
于 2010-06-08T09:17:41.580 回答
1

几乎所有 IBM 产品和技术文档都可以在 Internet 上找到。整理起来可能有点麻烦,但看看 Book Manger

为了回答您的具体问题, Language Environment Programming Reference告诉您几乎所有关于 LE 的知识。您可能想要公开的内存管理例程是:CEEGST(分配内存)和 CEEFRST(空闲内存)。

以下内容有点长,但它是一个完整的 IBM Enterprise COBOL 程序,它使用 LE 执行一些简单的内存管理工作。

  ***************************************************
  **                                               **
  ** DEMONSTRATION FOR LINKED LIST HANDLING        **
  **                                               **
  ***************************************************
   IDENTIFICATION DIVISION.
   PROGRAM-ID. LINKLST.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  RET-CDE                 PIC 9(3).
   01  HEAD-OF-LIST            POINTER.
   LINKAGE SECTION.
   01  LINK                              GLOBAL.
       02 DATA-PART            PIC 9(4).
       02 NEXT-PTR             POINTER.
   PROCEDURE DIVISION.
       CALL "BULDLST" USING HEAD-OF-LIST,
                            RET-CDE
       IF RET-CDE = ZERO THEN
          CALL "SHOWLST" USING HEAD-OF-LIST
          CALL "FREELST" USING HEAD-OF-LIST
          IF HEAD-OF-LIST = NULL THEN
             DISPLAY "LIST HAS BEEN FREED."
          END-IF
       END-IF
       GOBACK
       .
  ***************************************************
   IDENTIFICATION DIVISION.
   PROGRAM-ID BULDLST.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  I                       PIC 9(4).
   LINKAGE SECTION.
   01 HEAD-OF-LIST             POINTER.
   01 RET-CDE                  PIC 9(3).
   PROCEDURE DIVISION USING HEAD-OF-LIST, RET-CDE.
   MAINLINE SECTION.
       CALL "MEMALOC" USING BY REFERENCE HEAD-OF-LIST,
                            BY CONTENT   LENGTH OF LINK,
                            BY REFERENCE RET-CDE
       IF RET-CDE = ZERO THEN
          SET ADDRESS OF LINK TO HEAD-OF-LIST
          PERFORM VARYING I FROM 1 BY 1
                    UNTIL I > 4
                       OR RET-CDE > ZERO
             MOVE I TO DATA-PART OF LINK
             CALL "MEMALOC" USING BY REFERENCE NEXT-PTR OF LINK,
                                  BY CONTENT   LENGTH   OF LINK,
                                  BY REFERENCE RET-CDE
             IF RET-CDE = ZERO THEN
                SET ADDRESS OF LINK TO NEXT-PTR OF LINK
             END-IF
          END-PERFORM
          IF RET-CDE = ZERO THEN
             MOVE I TO DATA-PART OF LINK
             SET NEXT-PTR        OF LINK TO NULL
          END-IF
       END-IF
       GOBACK
       .
   END PROGRAM BULDLST.
  ***************************************************
   IDENTIFICATION DIVISION.
   PROGRAM-ID SHOWLST.
   DATA DIVISION.
   LINKAGE SECTION.
   01 HEAD-OF-LIST             POINTER.
   PROCEDURE DIVISION USING HEAD-OF-LIST.
   MAINLINE SECTION.
       SET ADDRESS OF LINK TO HEAD-OF-LIST
       PERFORM UNTIL ADDRESS OF LINK = NULL
           DISPLAY DATA-PART
           SET ADDRESS OF LINK TO NEXT-PTR OF LINK
       END-PERFORM
       GOBACK
       .
   END PROGRAM SHOWLST.
  ***************************************************
   IDENTIFICATION DIVISION.
   PROGRAM-ID FREELST.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 NXT-PTR                  POINTER.
   01 RET-CDE                  PIC 9(3).
   LINKAGE SECTION.
   01 HEAD-OF-LIST             POINTER.
   PROCEDURE DIVISION USING HEAD-OF-LIST.
   MAINLINE SECTION.
       MOVE ZERO TO RET-CDE
       PERFORM UNTIL HEAD-OF-LIST = NULL OR
                     RET-CDE NOT = ZERO
           SET ADDRESS OF LINK TO HEAD-OF-LIST
           SET NXT-PTR TO NEXT-PTR OF LINK
           CALL "MEMFREE" USING HEAD-OF-LIST, RET-CDE
           SET HEAD-OF-LIST TO NXT-PTR
       END-PERFORM
       GOBACK
       .
   END PROGRAM FREELST.
  ***************************************************
   IDENTIFICATION DIVISION.
   PROGRAM-ID MEMALOC COMMON PROGRAM.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  HEAPID                  PIC S9(9) BINARY.
   01  FC.
       02  CONDITION-TOKEN-VALUE.
       COPY  CEEIGZCT.
           03  CASE-1-CONDITION-ID.
               04  SEVERITY    PIC S9(4) BINARY.
               04  MSG-NO      PIC S9(4) BINARY.
           03  CASE-2-CONDITION-ID
                     REDEFINES CASE-1-CONDITION-ID.
               04  CLASS-CODE  PIC S9(4) BINARY.
               04  CAUSE-CODE  PIC S9(4) BINARY.
           03  CASE-SEV-CTL    PIC X.
           03  FACILITY-ID     PIC XXX.
       02  I-S-INFO            PIC S9(9) BINARY.
   LINKAGE SECTION.
   01 PTR-TO-MEM               POINTER.
   01 NBR-OF-BYTES             PIC S9(9) BINARY.
   01 RET-CDE                  PIC 9(3).
   PROCEDURE DIVISION USING PTR-TO-MEM, NBR-OF-BYTES, RET-CDE.
       MOVE 0 TO HEAPID
       CALL "CEEGTST" USING HEAPID,
                            NBR-OF-BYTES,
                            PTR-TO-MEM,
                            FC
       IF CEE000 OF FC  THEN
           MOVE ZERO TO RET-CDE
       ELSE
           DISPLAY "CEEGTST FAILED WITH: " MSG-NO OF FC
           MOVE 1 TO RET-CDE
           SET PTR-TO-MEM TO NULL
       END-IF
       GOBACK.
   END PROGRAM MEMALOC.
  ***************************************************
   IDENTIFICATION DIVISION.
   PROGRAM-ID MEMFREE COMMON PROGRAM.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  HEAPID                  PIC S9(9) BINARY.
   01  FC.
       02  CONDITION-TOKEN-VALUE.
       COPY  CEEIGZCT.
           03  CASE-1-CONDITION-ID.
               04  SEVERITY    PIC S9(4) BINARY.
               04  MSG-NO      PIC S9(4) BINARY.
           03  CASE-2-CONDITION-ID
                     REDEFINES CASE-1-CONDITION-ID.
               04  CLASS-CODE  PIC S9(4) BINARY.
               04  CAUSE-CODE  PIC S9(4) BINARY.
           03  CASE-SEV-CTL    PIC X.
           03  FACILITY-ID     PIC XXX.
       02  I-S-INFO            PIC S9(9) BINARY.
   LINKAGE SECTION.
   01 PTR-TO-MEM               POINTER.
   01 RET-CDE                  PIC 9(3).
   PROCEDURE DIVISION USING PTR-TO-MEM, RET-CDE.
       MOVE 0 TO HEAPID
       CALL "CEEFRST" USING PTR-TO-MEM,
                            FC
       IF CEE000 OF FC  THEN
           MOVE ZERO TO RET-CDE
       ELSE
           DISPLAY "CEEFRST FAILED WITH: " MSG-NO OF FC
           MOVE 1 TO RET-CDE
       END-IF
       GOBACK.
   END PROGRAM MEMFREE.
   END PROGRAM LINKLST.
  ***************************************************

该程序写道:

    0001
    0002
    0003
    0004
    0005
    LIST HAS BEEN FREED.

不是很令人兴奋,但确实展示了如何将一些东西串在一起。

于 2010-02-16T18:10:45.747 回答