From: not@any.adr   
      
   On Mon, 27 Sep 2004 02:47:13 -0500, Glenn Someone   
    wrote:   
      
   >OK, define a "Windows-minded memory grab" then.   
      
   1) Acquire memory only when needed.   
   2) Keep it only as long as needed.   
   3) Release it as soon as it's no longer needed.   
   4) Let the OS handle memory management tasks.   
      
      
   As in...   
      
   // load an existing project file   
   Procedure OpenProject;   
    var   
    pfn : ansistring; // project file name   
    fh : Fhandle; // file handle   
    Ptxt : pointer; // file data buffer   
    Stxt : longword; // size of file buffer   
    begin   
    SaveIfChanged;   
    pfn := getprojectfilename(True);   
    ptxt := nil;   
    if pfn = '' then   
    exit;   
    PrjName := pfn;   
    try   
    try   
    // open the file   
    fopenread(fh,pfn);   
    Stxt := fgetsize(fh);   
    // set up buffer   
    initmem(ptxt,stxt); < -- Memory is grabbed here.   
    // load file   
    fget(fh,ptxt,stxt);   
    // send to edit window   
    sendmessage(hwind[1],wm_settext,0,longint(ptxt));   
    sendmessage(hwind[1],em_setmodify,0,0);   
    except   
    messagebox(0,'Cannot load file','Error!',mb_iconwarning or mb_ok);   
    end;   
    finally   
    fclose(fh);   
    releasemem(ptxt); < -- Memory is released here.   
    end;   
    SetWindowText(hwind[0],Pchar(PrjName));   
    updatewindow(hwind[1]);   
    setfocus(hwind[1]);   
    end;   
      
      
   In the program I pulled that out of there are no preparitory memory grabs...   
   There are no huge blocks pre-allocated and no floating pool of memory reserved   
   for my program. All that is handled by windows. I just get and free chunks   
   of memory as needed.   
      
   As I said in my first comments on this topic... assume infinite memory, be   
   ready to deal with the assumption when it turns out to be false.   
      
   -----   
   Laura   
      
   (http://www.start.ca/users/ldblake)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|