Manipulating a User Space with Pointers

Manipulating a User

Space

with

Pointers

 

 

 

 

 

Some

languages,

 

such as

ILE

C', VisualAge++ for OS/400,C

ILE COBOL, ILE

RPG, COBOL, Pascal, and PL/I, support pointers. Pointers allow you to manip

information

more

rapidly

from

the

user space. To

use pointers with the

APIs,

you

should

understand

how

to:

 

Ÿ

Synchronize

between

two

or

more jobs

 

Ÿ

Use

offset

values

with

pointers

 

Ÿ

Update

usage

data

 

 

 

 

 

Synchronizing between Two or More Jobs

If you are using the Change User Space (QUSCHGUS) or Retrieve User

(QUSRTVUS) API to manipulate user spaces,

you do not need to synchroni

update and retrieve operations when

multiple

jobs

access

the

user

spa

APIs already do that for

you. However,

 

if you are using space

point

the

information

directly from

the

user

space,

you

should

synchronize

y

tion programs to avoid data errors. This

 

ensures that no two users upd

space at the same time,

which

can

cause

unpredictable

results.

 

 

Locks

are

typically

used

to

synchronize

 

two

jobs

on

the

system, and

y

user

spaces. To

synchronize

multiple

jobs,

you

can

use one of

the

fol

Ÿ

Compare

and

swap

(CMPSWP

MI

instructions)

 

 

 

 

 

 

 

 

 

Ÿ

Space

location

 

locks

(LOCKSL

and

UNLOCKSL

MI

instructions)

 

 

 

 

Ÿ

Object

locks

(LOCK

and

UNLOCK

MI

instructions)

 

 

 

 

 

 

 

Ÿ

Allocate Object

(ALCOBJ)

and Deallocate

Object

(DLCOBJ)

commands

 

 

The preceding list is ordered by relative performance where CMPSWP is

 

fastest. If you do not synchronize

two

or more jobs, multiple concurre

the

user

space

or

read

operations

can

 

occur

while

information

is

bein

As

a

result,

the

data

may

not

be

accurate.

 

 

 

 

 

 

 

Using Offset Values with Pointers

When using a pointer to manipulate the user space, you must:

1. Get a space pointer to the first byte (offset value of zero)

2.Retrieve the offset value of the information you want to use fro space.

3. Add that offset value to the space pointer value.

4.Use the space pointer value to directly refer to the information space.

See

“Changing a

User Space with an ILE RPG Program—Example” on page 2-20

for

an example

of this procedure.

Updating Usage Data

If you are using the Change User Space (QUSCHGUS) or Retrieve User

(QUSRTVUS) API to manipulate user

spaces,

you

do not need to update

 

data

information. If

you

directly retrieve data using pointers, your

 

grams

should

update

the

usage data information. To do this,

use

the

Q

API to update the date

last

changed

and use the QUSRTVUS

API

to

up

date

last

retrieved. You

do

not

need

to

do

this

for

each

retrieve

tion

to the user space,

but

you

should

do

this

once

within

each app

to maintain

accurate

usage data information.

 

 

 

 

 

 

2-16System API Programming V4R1

Page 36
Image 36
IBM Version 4 manual With, Manipulating a User, Synchronizing between Two or More Jobs, Using Offset Values with Pointers