Question about Temp-table BLOB field containing MEMPTR => memory Clean Up ?

altair

Member
Hello,

I have a program in which I have a temp-table in which I store some MEMPTR variable, like this (simplified code) :

Code:
DEFINE TEMP-TABLE tt-Chunk NO-UNDO
    FIELD Order AS INTEGER
    FIELD Data  AS BLOB
    FIELD Size  AS INT64
INDEX i IS PRIMARY UNIQUE fi-Order.

DEFINE VARIABLE mData AS MEMPTR   NO-UNDO.

/*set the MEMPTR with some data*/

/*start a loop that will create many records, like this : */

CREATE ttChunk.
ASSIGN
          ttChunk.Order =  iChunkNum
           ttChunk.Data  = mData
.

/*end of the loop*/

/* I do some processing with ttChunk, and after I need to do some clean up.*/

My question is : how to do the clean up properly ? (considering that I have BLOB field which points to MEMPTR) ?

Not sure that EMPTY TEMP-TABLE ttChunk (or DELETE ttChunk.) will actually delete my MEMPTR data variable content.

My approach will be to do :

Code:
DEFINE VARIABLE mChunkData AS MEMPTR NO-UNDO.

FOR EACH ttChunk EXCLUSIVE-LOCK                                       
:                                         
    COPY-LOB FROM OBJECT ttChunk.Data TO OBJECT mChunkData NO-CONVERT. /*retrieve the memptr data*/
    SET-SIZE(mChunkData) = 0.                                              /*delete the memptr data*/
    IF GET-SIZE(mChunkData) = 0  /*control if the data has actually been  deleted*/                     
    DELETE ttChunk.
END.

But do not know if this is required (maybe too much/slow down the perf for nothing) ?
Or maybe doing a simple EMPTY TEMP-TABLE ttChunk. (or FOR EACH ttChunk : DELETE ttChunk. END.) will be enough for that?

Thanks in advance.

Regards,
 
Last edited:

Stefan

Well-Known Member
Assign blob = mptr performs an implicit copy-lob as the following demonstrates:

Code:
define temp-table tt no-undo
   field lob as blob
   .
  
def var mptr as memptr no-undo.

set-size( mptr ) = 1000.

create tt.
tt.lob = mptr.

set-size( mptr ) = 0.

message string( length( tt.lob ) ) view-as alert-box.

So your blob is /not/ pointing to your memptr, it is a /copy/ of the memory your memptr is pointing to.
 

altair

Member
Ok thanks.
So i need to delete the memptr once stored in the temp-table.

What can I do with the BLOB field to ensure that its size is properly set to 0 (like the memptr).
Is deleting the record enough to ensure that the BLOB is also deleted (cleaned up from memory) as well ?

Thanks in advance.
 

Cringer

ProgressTalk.com Moderator
Staff member
Yes deleting the temp-table is enough. But you should definitely clear up the memptr, and do so for each iteration that populates the temp-table.
 
Top