Forum Post: RE: Handling System Error: Memory Violation

  • Thread starter Thread starter Frank Meulblok
  • Start date Start date
Status
Not open for further replies.
F

Frank Meulblok

Guest
- Does the API provide a way to get the size of the reply ? (most APIs do as it's considered good practice) - And do you need to allocate the memory for the reply, or does the API library allocate that itself ? If you need to allocate the memory: - Call the API to return the expected size - SET-SIZE a memptr to that size - Call the API to get the actual reply - SET-SIZE the memptr to 0 after you're done with it to deallocate the memory used. If the C++ library allocates the memory: - Call the API to get the reply - Call the API to return the expected size (some APIs will return the size and the data in different parameters of the same call) - SET-SIZE the memptr to the size of the message - as per documentation " If a MEMPTR variable is returned from a DLL or UNIX shared library routine that also allocates a memory region to it, then the SET-SIZE statement initializes the size of the existing region. The AVM does not allocate a new region. This allows the AVM to perform bounds checking on references to MEMPTR regions allocated outside ABL." - When you're done with the reply, DO NOT SET-SIZE it back to 0. Instead, there should be an API call to have the library de-allocate it, or it should take care of things behind the scenes. (If you do de-allocate the memptr while the C++ library still expects it to be allocated, bad things will happen)

Continue reading...
 
Status
Not open for further replies.
Back
Top