Path: utzoo!attcan!uunet!lll-winken!ames!oliveb!felix!arcturus!mitch From: mitch@arcturus.UUCP (Mitchell S. Gorman) Newsgroups: comp.lang.pascal Subject: Re: (re:)**3 function return value Summary: This may or may not be any help... Message-ID: <3968@arcturus> Date: 17 Mar 89 23:50:34 GMT References: <18654@adm.BRL.MIL> Organization: Rockwell International, Anaheim, CA Lines: 52 In article <18654@adm.BRL.MIL>, MATHRICH@umcvmb.missouri.edu (Rich Winkel UMC Math Department) writes: > Arghhh! I apologize for using so much bandwidth for this problem. It's my > fault for not giving a good example of what I want to do. Let me try again: > > function what(var where:string):string; > begin > what:=where; > delete(what,5,10); > end; > > Ok, so I need to: > 1. Use a VAR parameter to the function to avoid stacking a large variable, > 2. Avoid modifying the var parameter to the function, > 3. Avoid defining temp variables (which use up stack space) > 4. Do an operation which involves modifying a copy of the var parameter. Well, I'm going to reply specifically to the example that you list here, i.e., returning a truncated copy of the string. If you think that this'll work for whatever REAL manipulations you want to do, great. If not, well, I don't mind typing a lot of stuff, and potentially opening myself up to ridicule from every- one in netland!!! :^) Using this method will obviously depend on your ability to allocate dynamic mem- ory, but what about setting up a pointer to string[5], and assigning that dyn- amic variable to the original? In code form: var what : string[10]; temp : ^string[5]; begin ... temp^:=what; ... This won't take up much additional room in conventional memory, just a long word for the pointer address. When you assign a long string to a string variable of a lesser length, it automatically truncates. So here you avoid using a function call completely. I once had to write a best-guess type string pattern matching program, and trying to keep a couple thousand string[50] variables in an array can eat up memory REAL fast (ok, ok, I was young and foolish then! :^). What I wound up doing was keeping an array of pointers to strings; whence comes this idea you might want to consider. Have fun. Mitch @ Rockwell, Anaheim Disclaimer: I almost never run out of memory any mo