1 /* BEGINNING OF:  mrds_space_allocate.incl.pl1   * * * * * * * * * * * * * * */
 2 
 3 /* HISTORY:
 4 
 5    Created by:  Thanh Nguyen      01/15/85
 6 
 7  */
 8 
 9 
10 mrds_space_allocate:   proc (mrds_area_ptr, requested_word_size) returns (ptr);
11 
12 /* This function "allocates" the requested space in the temporary segment, if
13    the segment is "mrds area".  The space of allocation will not be free.  If
14    the area is full, this function returns a null pointer.  And the user has to
15    call mrds_area_initialize to reset the temporary segment back to the
16    beginning.  So, we never have the overflow on the area and the CPU
17    processing time for this allocation is low.  If the segment is not a
18    "mrds area", this function does a standard PL/I allocate.
19  */
20 
21           dcl     mrds_area_ptr           ptr;       /* ptr to the temporary segment. (INPUT) */
22           dcl     requested_word_size     fixed bin (35); /* number of words to be allocated. (INPUT) */
23 
24           dcl     actual_allocated_size   fixed bin (35); /* number of words to be allocated, rounded up to a 0 + mod 2 quantity. */
25           dcl     MRDS_AREA               char (8) init ("MRDSAREA");
26           dcl     (mod, null, ptr)        builtin;
27 
28           dcl     1 mrds_area             based (mrds_area_ptr),
29                     2 area_id             char (8),
30                     2 offset_to_free_word fixed bin (35), /* offset to the next free word in temp seg.  */
31                     2 length_free_space   fixed bin (35); /* length of remaining free space in temp seg.*/
32 
33           dcl     p_work_area             area (sys_info$max_seg_size) based (mrds_area_ptr);
34           dcl     alloc_value_ptr         ptr;
35           dcl     alloc_value             (actual_allocated_size) bit (36) based (alloc_value_ptr);
36 
37 
38           /* round up to even word boundary. */
39           actual_allocated_size = requested_word_size + mod (requested_word_size, 2);
40           if mrds_area_ptr = null then return (null);
41           else if mrds_area.area_id ^= MRDS_AREA then do;
42                /* must be a standard PL/I area. */
43                allocate alloc_value set (alloc_value_ptr) in (p_work_area);
44                return (alloc_value_ptr);
45           end;
46           else if actual_allocated_size <= length_free_space then do;
47                /* get pointer to next free word of area.  */
48                alloc_value_ptr = ptr (mrds_area_ptr, mrds_area.offset_to_free_word);
49                /* increase offset of remaining free space */
50                mrds_area.offset_to_free_word = mrds_area.offset_to_free_word + actual_allocated_size;
51                /* decrease length of remaining free space */
52                mrds_area.length_free_space = mrds_area.length_free_space - actual_allocated_size;
53                return (alloc_value_ptr);
54           end;
55           else return (null);
56 
57 
58 end mrds_space_allocate;
59 
60 /* END OF:     mrds_space_allocate.incl.pl1  * * * * * * * * * * * * * * * * */