Kbase 21654: How to load a file into memory using a MEMPTR variable?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  21/03/2008 |
|
Status: Verified
GOAL:
How to load a file into memory using a MEMPTR variable?
GOAL:
How to read a file into a MEMPTR?
GOAL:
How to write a MEMPTR to a file?
GOAL:
How to load a large file into Progress 4GL MEMPTR variables?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.1x
OpenEdge 10.x
FIX:
In a number of cases, it's desirable or even required to load a file entirely into memory before further processing. And in most cases, the file size can exceed 32K in size, meaning that the MEMPTR datatype should be used to hold the file - the other available data types are subject to a 32K size limit.
Similarly, there can be a requirement to write the contents of a MEMPTR variable to a file, either for storage or to work with it in another application.
For example, this can be the case when sending it over a socket connection (since the socket's READ and WRITE methods work on MEMPTRs only), or when manipulating files containing binary data.
The IMPORT and EXPORT statements can be used for these operations, as shown by the following examples:
To read a file into a MEMPTR:
/* make sure MEMPTR is sized correctly */
FILE-INFO:FILE-NAME = "SomeFileNameGoesHere".
SET-SIZE(SomeMemoryPointerGoesHere) = FILE-INFO:FILE-SIZE.
/* the actual read */
INPUT FROM "SomeFileNameGoesHere" BINARY NO-MAP NO-CONVERT.
IMPORT SomeMemoryPointerGoesHere.
INPUT CLOSE.
To write a MEMPTR out to a file:
OUTPUT TO "SomeFileNameGoesHere" BINARY NO-MAP NO-CONVERT.
EXPORT SomeMemoryPointerGoesHere.
OUTPUT CLOSE.