Kbase P18104: Memory Pointers Explained
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  2/8/2007 |
|
Status: Verified
GOAL:
Memory Pointers Explained
GOAL:
How Memory Pointers Work in Progress?
FACT(s) (Environment):
Progress 9.1x
FIX:
Memory Pointers
Memory is allocated and de-allocated using the SET-SIZE() statement.
The programmer is completely responsible for everything associated with this portion of memory.
The allocated memory cannot be added to widget-pools so the only thing we guarantee is that when the session goes away, the allocated memory also goes away.
There are functions to manipulate it, but Progress does not recognize the contents. T
he data type of a field defines what kind of data the field can store. All data types other than the MEMPTR data type are limited in size to 32K. MEMPTR variables can be any size.
Basic Example:
DEFINE VARIABLE Mptr AS MEMPTR NO-UNDO.
DEFINE VARIABLE CString AS CHARACTER NO-UNDO.
SET-SIZE(Mptr)= 53631385.
PUT-BYTE(Mptr,1) = 65.
PUT-STRING(Mptr,213) = ?SmartNews 2003?.
ASSIGN CString = GET-STRING(Mptr,1).
DISPLAY CString.
SET-SIZE(MPTR) = 0.
The SET?POINTER?VALUE Function
Progress supports a SET?POINTER?VALUE function that allows you to set the value of a MEMPTR variable. SET-POINTER-VALUE is particularly useful when accessing Windows Dynamic Link Library (DLLs) or UNIX shared library routines.
Example Using SET-POINTER-VALUE
The following example calls a DLL routine that returns a pointer to a structure, extracts an address at byte 5 of the structure, uses SET-POINTER-VALUE to assign the address to a Progress MEMPTR, and displays the character string at the address.
DEFINE VARIABLE person_struct AS MEMPTR NO-UNDO. /* pointer to structure */
DEFINE VARIABLE name AS MEMPTR NO-UNDO. /* pointer to name */
SET-SIZE(person_struct) = 8.
RUN person_info(OUTPUT person_struct).
SET-POINTER-VALUE(name) = GET-LONG(person_struct,5).
DISPLAY GET-STRING(name,1) FORMAT "x(50)".
SET-SIZE(person_struct)=0.
PROCEDURE person_info EXTERNAL "person.dll" PERSISTENT:
DEFINE OUTPUT PARAMETER person_struct AS MEMPTR NO-UNDO.
END PROCEDURE.